/*
  THE STYLE GUIDE  (David, 2026-10-31: "one passing style guide", "the one
  style sheet is the latest updates not the slop")

  One sheet, loaded LAST by the admin, contractor and contact panels (and
  first by the login page, for its tokens and buttons), that says once what
  the shared parts look like:

    1. Tokens         colours, radii, spacing, control sizes
    2. Base + type    page background, headings, muted text
    3. Page           main padding (laptop 28/32px, phone 8px), the sticky
                      title + search + New row
    4. Cards          .board list card, form cards (New forms, open ticket,
                      Profile, Settings), the "being edited" blue frame
    5. Forms          labels, field grids, tick boxes, field groups, the
                      Save / Cancel row, a button beside a field
    6. Buttons        .btn, primary / secondary / New (green) / danger,
                      icon buttons, chat icon boxes, Close
    7. Chips + pills  filter chips, status and priority pills
    8. Lists          tables on a laptop, every row its own tile on a phone
    9. Dialogs
   10. Small shared things: [hidden], fold chevrons, search clear (x)

  Rules
  - A fix to any of these goes HERE, never in admin.css / styles.css /
    panel-pages.css. scripts/checks/css-style-guide.mjs fails when another
    sheet defines one of this file's selectors again or resets a token.
  - The admin look is the reference ("contractor must look exactly like
    admin", 2026-10-26); the contact panel follows it too.
  - Phones (<= 700px): 8px page padding, 14px inside a form card, every list
    row its own tile, no box inside a box, icons top right on a tile.
  - New rules take a token or a class that exists here first; a per-screen
    exception stays in the panel sheet and names why.
*/

/* ------------------------------------------------------------------ */
/* 1. Tokens                                                           */
/* ------------------------------------------------------------------ */
:root {
  --ink: #1B1B1B;
  --ink-soft: color-mix(in srgb, var(--ink) 88%, #fff);
  --paper: #f3f4f6;          /* page background */
  --paper-2: #f9fafb;        /* table heading, hover */
  --fill: #f3f4f6;           /* pressed / hover fill on a white button */
  --white: #ffffff;
  --bg: #ffffff;             /* card background (older name, same colour) */
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --danger-ink: #b42318;     /* red WORDS: errors, Failed to send, Needs attention, delete in a menu (was six reds: #b42318 #b91c1c #c62828 #a11b1b #c0122a #dc2626) */
  --live: #316900;
  --live-soft: color-mix(in srgb, var(--live) 12%, #fff);
  --accent: #015D87;         /* dark blue: open tab, "being edited" frame */
  --accent-soft: color-mix(in srgb, var(--accent) 12%, #fff);
  --accent-hover: #014a6c;   /* hover on an --accent / --priority-normal fill */
  --link: #075081;           /* text links and uncoloured buttons / icons */
  --create: #125400;         /* every New … button, Up / healthy */
  --create-hover: #0d3f00;
  --ok: var(--create);
  --success: #2e7d32;        /* "Auto Saved..", checklist bar, up arrows (the fallback every rule used before the token existed) */
  --warn: #f59e0b;
  --warn-soft: #fffbeb;
  --warn-ink: #b45309;       /* amber WORDS: awaiting, contractor, publish pending (was five ambers) */
  --hold-soft: #eee8dc;      /* on hold / waiting on client pill fill */
  --ai: #7c3aed;             /* the Claude / AI buttons in editors */
  --dark: #13212c;           /* the one dark surface: first-visit tips, tour bar */
  --on-dark: #ffffff;        /* words and the solid button on --dark */
  --on-dark-soft: #d5e2ea;   /* body text on --dark */
  --on-dark-hover: #e6eef3;  /* hover / focus fill of the solid button on --dark (stays light, words stay dark) */
  --on-dark-line: rgba(255, 255, 255, .35);  /* outline button border on --dark */
  --on-dark-fill: rgba(255, 255, 255, .12);  /* outline button hover / focus fill on --dark */
  --on-dark-accent: #7cc4e4; /* spark, progress bar and focus ring on --dark */
  --priority-critical: #6F211F;
  --priority-important: #BA5700;
  --priority-normal: #015D87;
  --priority-critical-soft: color-mix(in srgb, var(--priority-critical) 12%, #fff);
  --priority-important-soft: color-mix(in srgb, var(--priority-important) 12%, #fff);
  --priority-normal-soft: color-mix(in srgb, var(--priority-normal) 12%, #fff);
  --shadow: 0 1px 2px rgba(27, 27, 27, 0.04), 0 10px 28px rgba(27, 27, 27, 0.05);
  --shadow-sm: 0 1px 2px rgba(27, 27, 27, 0.05);
  /* THE TYPE SCALE (David, 2026-11-01: "i thought you created one style
     sheet"). Every font-size in public/ is one of these; no sheet or script
     writes a px / pt / rem size of its own. scripts/checks/css-tokens.mjs
     fails a change that does. Small sizes carry --text-min, so phones never
     go below the menu. Chat boxes use the --chat-* pair (exempt from the
     phone minimum: "Apart from chat boxes"). */
  --text-xs: max(var(--text-min), 8.5pt);  /* counts, meta lines, tiny tags */
  --text-sm: max(var(--text-min), 9pt);    /* secondary text, hints, table meta */
  --text: 10pt;                            /* body, menu, fields, chips, pills */
  --text-md: 12pt;                         /* sub headings, big numbers in a row */
  --heading: 14pt;                         /* page and card headings */
  --heading-phone: 13pt;                   /* a page heading that shares its row on a phone (Dashboard + Select Dashboard) */
  --text-lg: 18pt;                         /* dashboard figures */
  --text-xl: 20pt;                         /* hero figures, login title */
  --chat-text-xs: 8.5pt;                   /* chat boxes only */
  --chat-text-sm: 9pt;                     /* chat boxes only */
  --text-input-phone: 16px;                /* phone field text: iPhone zooms the page under 16px */
  /* Smallest text allowed (David, 2026-11-01: "All other text headings etc eye
     brows sub headings should never be smaller than the mobile menu font").
     0 on a laptop, the phone menu's size (--text, 10pt) on a phone. Any text
     size under 10pt uses --text-xs / --text-sm (below), which carry it, so
     laptops keep their look and phones never go below the menu. Chat boxes
     (chat.css, internal-chat.css, voice.css) are left out ("Apart from chat
     boxes"); scripts/checks/css-text-min.mjs keeps it that way. */
  --text-min: 0px;
  --radius: 12px;            /* cards, tiles, dialogs */
  --radius-sm: 8px;          /* icon buttons */
  --radius-control: 5px;     /* fields, buttons, chips, pills */
  --accent-bar: 5px;         /* the coloured left bar on a card, row, toast or pin: one width everywhere (David 2026-11-01 "5 it is") */
  --control-height: 40px;    /* every field box and a button beside one */
  --btn-height: 29px;        /* a plain button; on phones the field height (below) */
  --btn-font: var(--text);   /* words on a button = a filter / priority chip's 10pt, laptop and phone (David, 2026-11-01: buttons "became too small compared to the correct ones being the priority size") */
  --icon-box: var(--btn-height); /* every square icon button (row pin/edit/comment/open, mic, paperclip, Close X, chat header icons) and the button beside one in a composer: as tall AND as wide as a plain button (David, 2026-11-01: "the height is the same, width as well as they are squares") */
  --count-tile: calc(var(--icon-box) * 0.8); /* unread count square on a chat row: 20% smaller than an icon box (David, 2026-11-01) */
  --icon-box-sm: 28px;       /* an icon button in a dense row: editor toolbar, side menu reorder, feed card, timesheet row */
  --icon-box-xs: 24px;       /* an icon inside a chip or a table heading: remove x, sort arrow, status icon */
  --chip-height: 29px;       /* every filter chip, pill and chat chip */
  --btn-height-lg: 48px;     /* the one big button: Confirm on the login code page */
  --menu-count-size: 22.5px; /* the side menu's count badge; every chat tile count matches it */
  --menu-count-pad-x: 6px;
  --count-size: 18px;        /* a round count badge on a chip or menu item */
  --radius-pill: 999px;      /* round count badges only; chips and pills use --radius-control */
  --btn-field-lift: calc((var(--control-height) - var(--btn-height)) / 2); /* lifts a 29px button onto a 40px field's centre line */
  --control-pad-x: 12px;
  --control-bg: #fff;
  /* A focused or open field: its one 1px border turns brand black. No ring or
     shadow around fields, dropdowns or search boxes (David 2026-11-01:
     "remove the shadows on these boxes everywhere"). */
  --control-focus-border: var(--ink);
  --space-1: 10px;
  --space-2: 16px;
  --space-3: 20px;
  --space-4: 30px;
  --board-pad-x: 22px;       /* inside a list card / Settings card */
  --board-pad-y: 16px;
  --form-pad-x: var(--space-4); /* inside a form card: the New ticket form */
  --form-pad-y: var(--space-4);
  --picker-width: clamp(240px, 25%, 100%); /* a picker alone on its row, laptop: a quarter of the box, never under 240px so names fit (David, 2026-11-02: "Choose a person can be 25% of the width") */
  --control-gap: 8px;        /* between buttons or chips in a row: New message · New group, All · Unread · Groups (David, 2026-10-31: one standard gap) */
  --icon-gap: var(--control-gap); /* between icon-only buttons in a row */
  --page-pad-phone: 8px;     /* page side padding on phones */
  /* Emojis in chat (/emoji-picker.js, David 2026-11-04): glyph sizes are emoji
     pictures, not text, so they sit outside the type scale. */
  --emoji-glyph: 48px;       /* a picker cell (twice the first size, David 2026-11-04) */
  --emoji-glyph-phone: 44px;
  --emoji-glyph-quick: 40px; /* the one-tap reaction row */
  --emoji-glyph-tab: 18px;   /* category tabs */
  --emoji-glyph-chip: 28px;  /* inside a reaction chip (doubled 2026-11-04) */
  --emoji-chip-h: 38px;      /* a reaction chip, tall enough for its emoji */
  --emoji-in-text: 2em;      /* an emoji among words in a message */
  --react-mine: color-mix(in srgb, var(--accent) 18%, transparent); /* your own reaction, visible on either bubble */
  --emoji-jumbo: 64px;       /* a message of only 1–3 emojis (doubled 2026-11-04) */
  --emoji-cell: 64px;
  --emoji-tab-cell: 36px;    /* category tabs keep their size */
  --emoji-cell-phone: 58px;
  --emoji-pop-w: 560px;
  --emoji-pop-h: 520px;
  --emoji-gap: 2px;
  --emoji-gap-sm: 4px;
  --emoji-pad: 6px;
  /* Sticky rows sit under the phone top bar + a running timer (measured by
     sidebar-toggle.js). */
  --sticky-top: calc(var(--obscured-top, 0px) + var(--header-h, 0px) + var(--timer-h, 0px)); /* under the phone top bar, a running timer and any browser strip over the page (Chrome on iPhone, sidebar-toggle.js) */
  font-family: Inter, system-ui, sans-serif;
  color-scheme: light;
}
/* Phones: every button is as tall as the fields and filter dropdowns (40px)
   so a row of dropdowns and a button reads as one row (David, 2026-11-01:
   "Let's make button height the same as the filters and drop downs so it all
   looks consistent"). --btn-field-lift falls to 0 by itself. Chat and comment
   composer buttons keep the icon-box size so they line up with mic/paperclip. */
@media (max-width: 760px) {
  :root { --btn-height: var(--control-height); }
}
@media (max-width: 700px) {
  /* Less padding inside boxes so fields use the width of the phone. */
  :root { --form-pad-x: 14px; --form-pad-y: 16px; --board-pad-x: 14px; --text-min: var(--text); }
}

/* ------------------------------------------------------------------ */
/* 2. Base + type                                                      */
/* ------------------------------------------------------------------ */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; font-size: var(--text); }

body {
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-weight: 400;
  line-height: 1.6;
}

h1, h2, h3 {
  margin: 0;
  font-size: var(--heading);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.eyebrow {
  margin: 0 0 var(--space-1);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.lede {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  max-width: 48ch;
  line-height: 1.45;
  font-weight: 400;
}
/* A page intro under the title runs across the title row, up to its buttons
   (David, 2026-11-02, Monitoring: "spread this out"). Every panel's page head. */
:is(.topbar-copy, .contractor-head-copy, .customer-head-copy) > .lede { max-width: none; }

/* No descriptions on phones (David, 2026-11-03: "I don't need the description on
   mobile"): page intros, section intros and dashboard card subtitles are left
   out at <= 700px in every panel. A page line holding data (project company /
   status / dates, Snapshot person) carries data-phone-keep and stays. */
@media (max-width: 700px) {
  :is(:is(.topbar-copy, .contractor-head-copy, .customer-head-copy) > .lede:not([data-phone-keep]),
    .settings-section > header > p, .settings-block > .lede, .lede.sps-lede, .dash-panel-sub) { display: none !important; }
}

/* Description paragraphs fold to one line on phones (David, 2026-11-03: "expand
   and collapse for the text description … in all sections on mobile").
   public/desc-fold.js adds .dfold only on a phone, only to text longer than one
   line; the chevron is the folded sections' bare chevron (section-fold.js). */
.dfold {
  position: relative;
  padding-right: 26px !important;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dfold:not(.is-open) {
  display: -webkit-box !important;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  overflow: hidden;
}
.dfold::after {
  content: "";
  position: absolute;
  top: 2px;
  top: calc((1lh - 18px) / 2);
  right: 2px;
  width: 18px;
  height: 18px;
  background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / 18px 18px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / 18px 18px no-repeat;
  transition: transform .15s ease;
}
.dfold.is-open::after { transform: rotate(180deg); }
.dfold:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-control); }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; }
p.status:empty { display: none; }

/* Uncoloured buttons and links take the link blue (iPhone gave them its
   system blue, laptop Chrome black). :where keeps this at zero weight. */
:where(button, input[type="button"], input[type="submit"], input[type="reset"], a:any-link) { color: var(--link); }
.ql-snow a { color: var(--link); }

/* ------------------------------------------------------------------ */
/* 3. Page                                                             */
/* ------------------------------------------------------------------ */
:is(.main, .contractor-main, .customer-main) {
  padding: 28px 32px 48px;
  background: var(--paper);
  width: 100%;
  min-width: 0;
}
@media (max-width: 700px) {
  :is(.main, .contractor-main, .customer-main) {
    --page-pad-x: var(--page-pad-phone);
    padding-left: var(--page-pad-x);
    padding-right: var(--page-pad-x);
  }
}

/* The title + search + New row (admin .topbar, contractor / contact head)
   stays in view under whatever sticks above it, with a hairline under it.
   On phones it spans the full width so tiles don't show beside it, and a
   head with no search box scrolls away with the page. */
:is(.topbar, .contractor-head, .customer-head) {
  position: sticky;
  top: var(--sticky-top, 0px);
  z-index: 30;
  background: var(--paper);
  box-shadow: 0 1px 0 var(--line);
  margin-bottom: 14px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 0;
}
.topbar-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
@media (max-width: 900px) {
  .topbar { margin-inline: calc(-1 * var(--page-pad-x, 16px)); padding-inline: var(--page-pad-x, 16px); }
  /* A hidden search (admin Tickets keeps #search but hides it, 2026-11-02) doesn't count. */
  .topbar:not(:has(.search:not(.hidden))) { position: static; box-shadow: none; }
  /* Buttons stay on the title row, at the right; a search takes its own full row. */
  .topbar { flex-flow: row wrap; align-items: center; row-gap: 10px; }
  .search input { width: 100%; }
}
@media (max-width: 700px) {
  :is(.contractor-head, .customer-head) { margin-inline: calc(-1 * var(--page-pad-x)); padding-inline: var(--page-pad-x); }
  :is(.contractor-head, .customer-head):not(:has(.search)) { position: static; box-shadow: none; }
}

.search { position: relative; }
.search input {
  width: min(100%, 280px);
}

/* ------------------------------------------------------------------ */
/* 4. Cards                                                            */
/* ------------------------------------------------------------------ */
/* A list card: the table runs edge to edge inside it. */
.board {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.board-meta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 12px 18px 8px;
  color: var(--muted);
  font-weight: 400;
}
.board-meta #record-count,
.board-meta .record-count { font-weight: 400; color: var(--ink); font-variant-numeric: tabular-nums; }
/* Phones: the count line keeps its words on one or two clean lines and the
   buttons (Clear filters, Sort, Expand, A–Z) wrap below it, on screen
   (David, 2026-11-06: "31 tickets · 3 sub tickets · David Wolfinger" went
   one word per line and Sort ran off the right edge). The words may take at
   most the row less room for the count, so they sit beside it, not under it.
   Check: ui-count-row-phone.mjs. */
@media (max-width: 700px) {
  .board-meta { flex-wrap: wrap; row-gap: var(--space-1); }
  .board-meta > #record-kind,
  .board-meta > .record-count + span { max-width: calc(100% - 3em); }
  .board-meta { align-items: baseline; }
  /* Buttons on the words' line share the words' baseline, so a 40px
     button is centred on a one-line count (David, 2026-11-16:
     "Right aligned and centred with text"; align-self: center dropped Sort
     below the words because the row is baseline-aligned). With Clear filters
     the buttons have their own row and stay centred on each other. */
  .board-meta > :is(button, .ticket-filter-clear, .tsort-bar) { align-self: center; }
  .board-meta:not(:has(> .ticket-filter-clear)) > :is(button, .tsort-bar) { align-self: baseline; }
}

/* A form card: a New / edit form opened in the page (admin .drawer.is-inline,
   the ticket desk, the contractor and contact New ticket forms, Profile and
   other .details-form cards that aren't already inside a card) and a
   Settings card. Same white card, same padding as the New ticket form. */
.drawer.is-inline,
.ticket-desk-panel,
.time-form.new-ticket-form,
.new-ticket-form.dd-card,
.details-form:not(:is(.board, .drawer, dialog, .dash-card, .member-row-body, .details-layout) *) {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--form-pad-y) var(--form-pad-x);
}
.ticket-desk-panel { scroll-margin-top: 96px; }
.new-ticket-form.dd-card { margin: 0 0 20px; }
.details-form { display: grid; gap: 14px; min-width: 0; }
/* Admin's New / edit form opens in the page, not as a side drawer: a
   full-width card under the filters. */
.drawer.is-inline {
  position: static;
  inset: auto;
  width: auto;
  max-width: none;
  margin: 0 0 var(--space-4);
  overflow: visible;
  animation: none;
}
.settings-section {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: var(--board-pad-y) var(--board-pad-x);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  scroll-margin-top: 72px;
  min-width: 0;
}
.settings-section > header h2,
.settings-block.settings-section > h2 { margin: 0; font-size: var(--text-md); font-weight: 500; text-align: left; }
.settings-section > header p,
.settings-block.settings-section > .lede { margin: 2px 0 0; color: var(--muted); font-size: var(--text); max-width: 72ch; }
@media (max-width: 700px) {
  /* No box inside a box: a form card inside another card drops its edge and
     lines its fields up with the card it sits in. */
  :is(.board, .dash-card) .ticket-desk-panel { padding-left: 12px; padding-right: 12px; border: 0; box-shadow: none; }
}

/* The section being edited is framed in dark blue, in every panel (David,
   2026-10-30: "highlighting the border with the blue every time a section is
   being edited", "roll this out everywhere"). An outline sits on the card's
   own border, so nothing moves.
   - A form that is open for editing (the ticket desk, a New / edit form in
     the page, the contractor / client New ticket form) is framed the whole
     time it is open (David, 2026-10-31 "Border not blue" on the New
     administrator form before a field was touched), and nothing inside it
     lights on its own.
   - Anywhere else, the innermost card holding the control you are using
     lights: a text box, date, dropdown (native or ours, also while its list
     is open), editor, tick box or radio. One section at a time; search boxes,
     filter bars, list tables and bulk ticks don't count.
   The Company Overview's green "adding" glow keeps its colour. Add a card's
   class to a list to include it; data-no-edit-frame opts a part out.
   The contractor page form (.person-form) fills its card, so the card
   lights, not a box inside it (David, 2026-11-02: "entire tile border needs
   to be the blue").
   Check: scripts/checks/ui-edit-section-frame.mjs. */
:is(.ticket-desk-panel, .ticket-card.is-form, .new-ticket-form, .drawer.is-inline, .campaign-form):not(.co-add *),
:is(.board, .drawer, .ticket-split-side, .ticket-card, .ctv-col > .ctv-comments, .settings-section, .settings-card, .details-form:not(.person-form), .dash-card, .dash-panel, .comment-thread > .comment-form, .comment-pop .comment-form, .note-card, .campaign-editor, .status-editor, .quick-create, .co-quick, .co-card, .website-card, .website-info, .company-website, .ticket-checklist, .ticket-checklist-c, .import-card, .module-card, .spt, .spr, .spg, .cloud-card, .site-fixes, .issue-card, .member-card, .project-card, .confirm-dialog):has(:is(:is(input:not([type="button"], [type="submit"], [type="reset"], [type="hidden"], [type="range"], [type="color"], [type="file"], [type="search"]), textarea, select, [contenteditable="true"], .gsel-trigger, .field-picker, .dt-pick button):focus, :is(.gsel-trigger, .field-picker)[aria-expanded="true"]):not(:is(.filters, .filter-tile, .panel-toolbar, .topbar, table, .bulk-bar, .chat-row-lead, .dd-switch, .gsel-pop, [data-no-edit-frame]) *)):not(:has(:is(.board, .drawer, .ticket-split-side, .ticket-card, .ctv-col > .ctv-comments, .settings-section, .settings-card, .details-form:not(.person-form), .dash-card, .dash-panel, .comment-thread > .comment-form, .comment-pop .comment-form, .note-card, .campaign-editor, .status-editor, .quick-create, .co-quick, .co-card, .website-card, .website-info, .company-website, .ticket-checklist, .ticket-checklist-c, .import-card, .module-card, .spt, .spr, .spg, .cloud-card, .site-fixes, .issue-card, .member-card, .project-card, .confirm-dialog, .ticket-desk-panel, .ticket-card.is-form, .new-ticket-form) :is(:is(input:not([type="button"], [type="submit"], [type="reset"], [type="hidden"], [type="range"], [type="color"], [type="file"], [type="search"]), textarea, select, [contenteditable="true"], .gsel-trigger, .field-picker, .dt-pick button):focus, :is(.gsel-trigger, .field-picker)[aria-expanded="true"]):not(:is(.filters, .filter-tile, .panel-toolbar, .topbar, table, .bulk-bar, .chat-row-lead, .gsel-pop, [data-no-edit-frame]) *))):not(:is(.ticket-desk-panel, .ticket-card.is-form, .new-ticket-form, .drawer.is-inline, .campaign-form) *):not(.co-glow, .co-add > *) {
  outline: 1px solid var(--accent, #015D87);
  outline-offset: -1px;
  /* The frame follows the card's corners (same radius as the others).
     !important because phone rules that drop a card's edge also square it. */
  border-radius: var(--radius, 12px) !important;
}

/* An open Filter box on phones is framed like a section being edited (PR #283,
   David 2026-10-31: "Active box doesn't have the blue border"). The shared
   Tickets filter bar (ticket-filters.js, all three panels) folds behind the
   Filter button at <=700px; while it is open its filters tile carries the
   frame. Inside a card that drops the tile's edge (company Tickets tab with a
   ticket open) it keeps 12px inside the frame so nothing touches it. Laptop
   filters never fold, so they are never framed. */
@media (max-width: 700px) {
  .filters.filter-tile.has-fold.is-open > .filter-row {
    padding: 12px;
    outline: 1px solid var(--accent, #015D87);
    outline-offset: -1px;
    border-radius: var(--radius, 12px) !important;
  }
  /* Inside a card (company Tickets tab) the frame reaches out towards the
     card's edge instead of pushing the fields further in, so they stay the
     card's own padding in (ui-mobile-ticket: no inner box, <= 20px). */
  .board .filters.filter-tile.has-fold.is-open > .filter-row { margin-left: -8px; margin-right: -8px; padding-left: 8px; padding-right: 8px; }
}

/* ------------------------------------------------------------------ */
/* 5. Forms                                                            */
/* ------------------------------------------------------------------ */
/* A field: its name above its box. :where keeps the weight low so a tick
   box (label.check) or an inline tick keeps its own layout. */
:where(.drawer-form, .details-form, .note-composer, .time-form, .ticket-desk-form, .new-ticket-form, .confirm-dialog) label,
:where(.drawer-form) fieldset legend {
  display: grid;
  gap: var(--space-1);
  align-content: start;
  font-size: var(--text);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}
:where(.drawer-form, .details-form) label[hidden] { display: none; }

/* Text boxes fill their column; tick boxes, radios and dates keep their size. */
:where(.drawer-form, .details-form, .time-form) input:not([type="checkbox"], [type="radio"], [type="color"]),
:where(.drawer-form, .details-form, .time-form) select,
:where(.drawer-form, .details-form, .note-composer) textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
:where(.drawer-form, .details-form, .time-form) input:is([type="date"], [type="datetime-local"], [type="time"], [type="month"], [type="week"]) {
  width: 13.5em;
  min-width: 0;
  max-width: 100%;
  justify-self: start;
}

/* Fields side by side: three, two, or a pair (Start | Due). One per row on phones. */
.field-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); min-width: 0; max-width: 100%; }
.field-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); min-width: 0; }
.field-grid-3.field-grid-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3, 16px); }
:is(.field-grid-3, .field-grid-2) > :is(label, .radio-field) { min-width: 0; }
@media (max-width: 700px) {
  :is(.field-grid-3, .field-grid-3.field-grid-pair, .field-grid-2, .field-pair) { grid-template-columns: 1fr; }
}
@container (max-width: 560px) {
  .field-grid-3 { grid-template-columns: 1fr; }
}

/* A tick box: box, then words (and a hint under the words). */
label.check {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}
label.check > .hint { display: block; grid-column: 2; color: var(--muted); }

/* Accounts email with its "Copy contact" tick to the right (accounts-copy.js).
   Ticked: the box shows the Contact email, greyed and read-only. */
.accounts-email { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--space-3, 16px); align-items: end; min-width: 0; }
.accounts-email > label.check.accounts-copy { display: inline-flex; align-items: center; gap: 8px; min-height: var(--control-height); margin: 0; white-space: nowrap; cursor: pointer; }
.accounts-email > label.check.accounts-copy input { margin: 0; }
.accounts-email input[name="accountsEmail"]:read-only { background-color: var(--paper-2); color: var(--muted); }

/* A run of related fields (Channel, permissions) under one plain heading. */
.radio-field { display: grid; gap: var(--space-1); min-width: 0; margin: 0; padding: 0; border: 0; }
.radio-field legend { padding: 0; font-size: var(--text); font-weight: 400; text-transform: none; }
.field-group {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line, #e3e6ea);
  border-radius: 8px;
}
.field-group legend { padding: 0 4px; font-size: var(--text); font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.field-group-body { display: grid; gap: 12px; }
/* Phones: no box inside a box (David, 2026-10-28 / 2026-10-31 campaign form):
   the group loses its frame and its legend reads as a plain heading. */
@media (max-width: 700px) {
  .field-group { padding: 0; border: 0; border-radius: 0; }
  .field-group legend { padding: 0; margin: 0 0 2px; color: var(--ink); }
}

/* Save / Cancel (and any other action row) at the right. */
.drawer-actions,
.form-actions,
.confirm-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--control-gap); flex-wrap: wrap; }
.drawer-actions { margin-top: 8px; }

/* A button beside a field (+ New project, Add sub ticket, Add website …):
   a plain --btn-height button centred on the field's box, never hanging off
   its bottom edge (David, 2026-10-31). It was the field's 40px on laptops
   too until David, 2026-11-04 ("button size wrong" on Add sub ticket): every
   button is the standard 29px on a laptop; phones are 40px anyway, the
   field's height, so nothing changes there. Put the button next to the label
   in one of these rows, or give the row data-field-row. The tripled class
   outranks the text-button rule below. The company Websites add row
   (.company-website-add) has its own grid in admin.css (name · address · Add,
   the address on its own line on phones, PR #288) and is only kept out of the
   29px rule below: making it flex here squeezed the address box to 91px. */
:is(.subticket-parent-field, .inbound-pick, .website-info-add, .website-url, [data-field-row]) {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  min-width: 0;
}
:is(.subticket-parent-field, .inbound-pick, .website-info-add, .website-url, [data-field-row]) > label { flex: 1 1 auto; min-width: 0; }
:is(.subticket-parent-field, .inbound-pick, .website-info-add, .website-url, [data-field-row]) > .btn.btn.btn:not(.btn-icon) {
  height: var(--btn-height);
  min-height: var(--btn-height);
  flex: none;
  align-self: flex-end;
  margin-bottom: var(--btn-field-lift);
}
:is(.subticket-parent-field, .inbound-pick, .website-info-add, .website-url, [data-field-row]) > .btn-icon { align-self: flex-end; margin-bottom: calc((var(--control-height) - var(--icon-box)) / 2); }

/* Every other button beside a field keeps --btn-height (29px laptop, field
   height on phones) and sits on the field's
   centre line (PR #290, David 2026-10-31: "Anywhere there is a field and
   button need to centre the button", "This is everywhere"). Rows that wrap
   the field with its label above it (label > select, the phone filter
   dropdown) lined the button up with the bottom of the field, 5.5px low: they
   drop the button to the field's bottom line and lift it half the height
   difference. Rows where the field is a direct sibling centre the button on
   it. The named rows above are left out: their button is the field's height.
   Kept honest by scripts/checks/ui-field-button-align.mjs on every screen. */
:has(> :is(label, .chip-select, .field) :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]), select)):not(.subticket-parent-field, .inbound-pick, .company-website-add, .website-info-add, .website-url, [data-field-row]) > :is(.btn.btn:not(.btn-icon), .add-docked) {
  align-self: flex-end;
  margin-bottom: var(--btn-field-lift);
}
:has(> :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]), select, .gsel)):not(.subticket-parent-field, .inbound-pick, .company-website-add, .website-info-add, .website-url, [data-field-row]) > :is(.btn, .add-docked) {
  align-self: center;
}

/* No full-width buttons or pickers on a laptop (David, 2026-11-02: "i dont
   like this full width style of buttons and fields anywhere on the site. Add
   can go on the same line, Choose a person can be 25% of the width").
   - A button is as wide as its words. Grid layouts stretch their children by
     default, so a button placed straight in a grid filled the row (chat People
     "Add"); justify-self: start stops that. Zero specificity: a row that
     centres or right-aligns its button still wins.
   - A picker with its button: wrap both in .pick-row (with data-field-row for
     the field-height button above). The picker takes --picker-width, the
     button sits on the same line.
   - A picker alone on its row in a wide box: width: var(--picker-width).
   Text boxes and big text areas (name, description, message) still fill
   their column: they are where people type. Phones keep their full-width
   rows (Status #323 and the rest): the picker grows, the button stays beside it.
   Kept honest by scripts/checks/ui-no-full-width.mjs. */
@media (min-width: 761px) {
  :where(.btn, a.btn) { justify-self: start; }
  .pick-row > label { flex: 0 1 var(--picker-width); width: var(--picker-width); max-width: 100%; }
}
.pick-row { display: flex; align-items: flex-end; gap: var(--control-gap); min-width: 0; }
.pick-row > label { display: grid; gap: 6px; min-width: 0; }
.pick-row > label :is(select, .gsel) { width: 100%; min-width: 0; }
@media (max-width: 760px) {
  .pick-row > label { flex: 1 1 auto; }
}

/* ------------------------------------------------------------------ */
/* 6. Buttons                                                          */
/* ------------------------------------------------------------------ */
.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: var(--btn-font);
  font-weight: 400;
  /* Normal case on every button (David, 2026-11-01: "upper and lower so its consistent"); never uppercase. */
  letter-spacing: 0;
  text-transform: none;
  border-radius: var(--radius-control);
  padding: 11px 16px;
}
/* A button with an icon then words: the words' capitals sit level with the
   icon's middle, not their line box with its descender room. */
.btn > svg + span { text-box: trim-both cap alphabetic; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Every text button is --btn-height tall: a filter chip's 29px on laptops,
   a field's 40px on phones. The
   doubled class outranks the per-area .x .btn padding overrides; square
   icon buttons keep their own size. */
.btn.btn:not(.btn-icon) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-height);
  min-height: var(--btn-height);
  padding: 0 12px;
  line-height: 1;
  white-space: nowrap;
}
@supports (text-box: trim-both cap alphabetic) {
  /* Exact vertical centring for text-only buttons: trim the line box to the
     capitals and pad the rest. */
  .btn.btn:not(.btn-icon):not(:has(svg)) {
    display: inline-block;
    height: var(--btn-height);
    line-height: 1;
    text-align: center;
    vertical-align: middle;
    text-box: trim-both cap alphabetic;
    padding-block: calc((var(--btn-height) - 1cap) / 2 - 1px);
  }
  .btn.btn-primary:not(.btn-icon):not(:has(svg)) {
    padding-block: calc((var(--btn-height) - 1cap) / 2);
  }
}

/* Send (and any word button) under a chat or comment box is the icon boxes'
   height and corner, so Close X, mic, paperclip and Send line up as one row
   (David, 2026-11-01: "The close icon box needs to be the same size as the
   other boxes"; Send was 29px beside 34px boxes). Icon boxes are now the
   plain button's height, so this row matches every other button too. */
:is(.chat-composer-row, .ichat-composer-bar, .comment-send-row) > .btn.btn.btn:not(.btn-icon) {
  height: var(--icon-box);
  min-height: var(--icon-box);
  border-radius: var(--radius-sm, 8px);
}
@supports (text-box: trim-both cap alphabetic) {
  :is(.chat-composer-row, .ichat-composer-bar, .comment-send-row) > .btn.btn.btn:not(.btn-icon):not(:has(svg)) {
    height: var(--icon-box);
    padding-block: calc((var(--icon-box) - 1cap) / 2);
  }
}

/* Primary: solid brand black. */
.btn-primary {
  background: var(--ink);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--ink-soft); }

/* Buttons on the dark surface (first-visit tip, tour bar). The global hover
   above turns a primary button dark grey, which on the white tip button left
   dark words on dark grey (David, 2026-11-01 "overstate bug": Got it vanished
   on hover). Here every state keeps its words readable, and nothing moves. */
:is(.tip-card, .tour-bar) .btn.btn.btn {
  min-height: var(--btn-height);
  padding-inline: 12px;
  font-size: max(var(--text-min, 0px), var(--btn-font));
  box-shadow: none;
  transform: none;
}
:is(.tip-card, .tour-bar) .btn.btn.btn.btn-primary,
:is(.tip-card, .tour-bar) .btn.btn.btn.btn-primary:is(:hover, :focus-visible, :active):not(:disabled) {
  color: var(--dark);
  border: 1px solid var(--on-dark);
}
:is(.tip-card, .tour-bar) .btn.btn.btn.btn-primary { background: var(--on-dark); }
:is(.tip-card, .tour-bar) .btn.btn.btn.btn-primary:is(:hover, :focus-visible, :active):not(:disabled) {
  background: var(--on-dark-hover);
  border-color: var(--on-dark-hover);
}
:is(.tip-card, .tour-bar) .btn.btn:not(.btn-icon):not(.btn-primary):not(.btn-danger):not(.btn-action):not(.danger),
:is(.tip-card, .tour-bar) .btn.btn:not(.btn-icon):not(.btn-primary):not(.btn-danger):not(.btn-action):not(.danger):is(:hover, :focus-visible, :active):not(:disabled) {
  background: transparent;
  color: var(--on-dark);
  border: 1px solid var(--on-dark-line);
}
:is(.tip-card, .tour-bar) .btn.btn:not(.btn-icon):not(.btn-primary):not(.btn-danger):not(.btn-action):not(.danger):is(:hover, :focus-visible, :active):not(:disabled) {
  background: var(--on-dark-fill);
  border-color: var(--on-dark);
}
:is(.tip-card, .tour-bar) .btn:focus-visible {
  outline: 2px solid var(--on-dark-accent);
  outline-offset: 2px;
}

/* Secondary (ghost or plain): white with a brand-black outline, the same as
   the filter chips. */
.btn-ghost {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn.btn:not(.btn-icon):not(.btn-primary):not(.btn-danger):not(.btn-action):not(.danger) {
  background: var(--bg, #fff);
  border: 1px solid var(--ink);
  color: var(--ink);
}
.btn.btn:not(.btn-icon):not(.btn-primary):not(.btn-danger):not(.btn-action):not(.danger):hover:not(:disabled) {
  background: var(--fill, #f3f4f6);
}

/* New …, Add …, Create …: solid green, every panel (David, 2026-11-01). */
.btn.btn-create, .btn-primary.btn-create { background: var(--create); border-color: var(--create); color: #fff; }

/* A button while its request runs (David, 2026-11-01: "make this green with
   pulsating circle"): green, a pulsing dot before the label ("Checking…"),
   full strength even though it is disabled. busy-button.js sets the class;
   markup painted while busy adds class is-busy + aria-busy="true". */
.btn.btn.is-busy:not(.btn-icon):not(.btn-primary):not(.btn-create):not(.btn-danger) {
  border-color: var(--create);
  color: var(--create);
  background: var(--white);
}
.btn.btn.is-busy { cursor: progress; }
.btn.btn.is-busy:disabled { opacity: 1; }
.btn.btn.is-busy:not(.btn-icon)::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: middle;
  animation: busy-pulse 1.2s ease-in-out infinite;
}
@keyframes busy-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.7); }
}
@media (prefers-reduced-motion: reduce) {
  .btn.btn.is-busy:not(.btn-icon)::before { animation: none; }
}
.btn.btn-create:hover, .btn-primary.btn-create:hover { background: var(--create-hover); border-color: var(--create-hover); color: #fff; }
.btn.btn-create:focus-visible { outline: 2px solid var(--create); outline-offset: 2px; }

/* Destructive = Critical red, secondary actions = Normal blue. */
.btn-danger, .btn.btn-ghost.danger { background: var(--priority-critical); border-color: var(--priority-critical); color: #fff; }
.btn-danger:hover, .btn.btn-ghost.danger:hover { background: #561917; border-color: #561917; color: #fff; }
.btn.btn-action { background: var(--priority-normal); border-color: var(--priority-normal); color: #fff; }
.btn.btn-action:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--white); }

/* The sizing rule above sets display, which would beat the hidden attribute. */
.btn[hidden],
.btn.hidden,
.chip[hidden],
.chat-chip[hidden],
.dash-panel-action[hidden] { display: none !important; }

/* Icon-only button: a white square the plain button's height (--icon-box), light edge, link-blue icon. .icon-btn
   (the × on an in-page form) is the same button. */
/* The box is set with no weight (:where) so a panel can still hide one of
   these (`.sidebar-toggle { display: none }` on phones) with a plain class. */
:where(.btn-icon, .icon-btn) { display: grid; place-items: center; }
.btn-icon,
.icon-btn {
  width: var(--icon-box);
  height: var(--icon-box);
  min-height: var(--icon-box);
  padding: 0;
  letter-spacing: 0;
  text-transform: none;
  appearance: none;
  font: inherit;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  color: var(--link);
  cursor: pointer;
}
.icon-btn { font-size: var(--heading); line-height: 1; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon.danger { color: var(--danger); }
.btn-icon.is-live { background: var(--danger-soft); border-color: #fecaca; }
:is(.btn-icon, .icon-btn):hover:not(:disabled) { background: var(--fill, #f3f4f6); }

/* Icon-only buttons in a row, one gap everywhere. */
.row-actions { display: flex; flex-wrap: wrap; gap: var(--icon-gap); }
td .row-actions { flex-wrap: nowrap; }
td.col-actions .row-actions { justify-content: flex-end; }
/* Word buttons in an Actions cell (company Contractors / Admins: Projects,
   Unassign) stay together on one line, the standard gap apart (David,
   2026-11-02); the icons may wrap, the words never stack. */
.row-actions > .text-actions { display: inline-flex; flex-wrap: nowrap; align-items: center; gap: var(--icon-gap); }

/* One look for every icon button in a chat header or message box: Back,
   Create ticket, Call, Video, Archive, Attach, Close. .icon-box-phone is a
   word button on a laptop that becomes this icon box on phones. Doubled
   classes outrank the secondary-button rule above. */
.icon-box.icon-box,
.btn-icon.icon-box {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--icon-box);
  height: var(--icon-box);
  min-height: var(--icon-box);
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm, 8px);
  background: #fff;
  box-shadow: var(--shadow-sm);
  color: var(--link);
  cursor: pointer;
}
.icon-box.icon-box:hover:not(:disabled) { background: var(--fill, #f3f4f6); }
.icon-box.icon-box svg { width: 18px; height: 18px; }
.icon-box[hidden],
.icon-box.hidden { display: none !important; }
.icon-box-phone > svg { display: none; }
/* Every Close (X) button draws the same X: Lucide x, 18px, stroke 2 (PR #285,
   David 2026-10-31: "same everywhere ... same x font"). Phones: each is also the
   same --icon-box solid New ticket green (--create) with a white X, so it stands out
   ("Make it solid like the new button", "Not red", "This is a phone change
   only"). Laptops keep each button's own box. 760px = where chats switch to
   their phone layout (the chat Close only shows there). */
.close-solid.close-solid svg { width: 18px; height: 18px; stroke-width: 2; flex: none; }
@media (max-width: 760px) {
  .close-solid.close-solid,
  .close-solid.close-solid:not(:disabled) {
    display: inline-grid;
    place-items: center;
    box-sizing: border-box;
    width: var(--icon-box);
    min-width: var(--icon-box);
    height: var(--icon-box);
    min-height: var(--icon-box);
    padding: 0;
    border: 1px solid var(--create, #125400);
    border-radius: var(--radius-sm, 8px); /* the icon boxes' corner, so it reads the same size beside them (David, 2026-11-01) */
    background: var(--create, #125400);
    box-shadow: none;
    color: #fff;
    font-size: 0;
    line-height: 0;
    opacity: 1;
  }
  .close-solid.close-solid:hover:not(:disabled),
  .close-solid.close-solid:focus-visible { border-color: var(--create-hover, #0d3f00); background: var(--create-hover, #0d3f00); color: #fff; }
  .close-solid.close-solid svg { color: #fff; stroke: currentColor; }
  .close-solid[hidden] { display: none !important; }
}
@media (max-width: 760px) {
  .btn.btn.btn.icon-box-phone:not(.btn-primary) {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: var(--icon-box);
    height: var(--icon-box);
    min-height: var(--icon-box);
    padding: 0;
    border: 1px solid var(--line) !important;
    border-radius: var(--radius-sm, 8px) !important;
    background: #fff !important;
    box-shadow: var(--shadow-sm) !important;
    color: var(--link) !important;
  }
  .icon-box-phone > svg { display: block; width: 18px; height: 18px; }
  .icon-box-phone > [data-word] { display: none; }
}

/* ------------------------------------------------------------------ */
/* 7. Chips + pills                                                    */
/* ------------------------------------------------------------------ */
/* A filter chip: the box of a pill (29px), brand-black outline; hover and
   selected = solid brand black. */
.chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  width: auto;
  height: var(--chip-height);
  padding: 0 11px;
  border: 1px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-size: var(--text);
  font-weight: 400;
  line-height: 1;
  border-radius: var(--radius-control);
  text-decoration: none;
  text-transform: none;
  white-space: nowrap;
  box-shadow: none;
  cursor: pointer;
}
.chip:hover,
.chip.is-active { background: var(--ink); color: var(--white); border-color: var(--ink); }
.chip.is-active:hover { background: var(--ink-soft); border-color: var(--ink-soft); }

/* A status / priority pill. */
.pill {
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  height: var(--chip-height);
  padding: 0 11px;
  font-size: var(--text);
  font-weight: 400;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: capitalize;
  white-space: nowrap;
}
button.pill { appearance: none; border: 0; cursor: pointer; font: inherit; font-size: var(--text); font-weight: 400; }
button.pill:hover,
button.pill:focus-visible { filter: brightness(0.96); }
.pill:is(.inactive, .archived, .closed) { background: var(--paper); color: var(--muted); }
.pill.open { background: var(--fill); color: var(--muted); }
.pill:is(.in-progress, .main, .completed, .publish-published) { background: var(--live-soft); color: var(--live); }
.pill.overdue { background: var(--danger-soft); color: var(--danger-ink); }
.pill.awaiting { background: var(--warn-soft); color: var(--warn-ink); }
.pill:is(.normal, .low, .priority-normal) { background: var(--priority-normal); color: #fff; }
.pill:is(.important, .medium, .priority-important) { background: var(--priority-important); color: #fff; }
.pill:is(.critical, .urgent, .high, .priority-high, .priority-critical) { background: var(--priority-critical); color: #fff; }
/* Priority icons (/icons.js) sit in front of the label. */
.priority-icon { width: 14px; height: 14px; flex: 0 0 auto; }
.pill:has(> .priority-icon),
.chip:has(> .priority-icon) { gap: 5px; }

/* A row of chips or buttons: one gap everywhere (David, 2026-10-31: "make it
   a standard gap between the larger buttons and the smaller style across the
   whole site"). Filter chips, chat filters, New message · New group, dialog
   buttons, docked Add buttons all read --control-gap; never a number. */
.filter-chips,
.filter-scopes {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--control-gap);
}
.filter-scopes { column-gap: var(--space-3); } /* dropdown rows keep their wider columns */

/* Menu count: the side menu's unread / waiting count (admin nav, contractor
   and client panel nav) and every chat tile's count (dashboard, company Chats
   tab, Communication page), one look (David, 2026-11-01: "make it the same as
   the menu"). */
.menu-count,
.nav-list .count:not(:empty),
.nav-list .count.is-hot,
.panel-nav .chat-unread,
.chat-dash-toggle [data-fold-unread] {
  display: inline-grid;
  place-items: center;
  min-width: var(--menu-count-size);
  height: var(--menu-count-size);
  padding: 0 var(--menu-count-pad-x);
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--white);
  font-size: var(--text);
  font-weight: 400;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  opacity: 1;
}
.menu-count[hidden],
.chat-dash-toggle [data-fold-unread][hidden] { display: none; }

/* Unread count on a chat row: a square tile, not a small pill (David,
   2026-10-31), 20% smaller than an icon button since 2026-11-01; it sits
   between the time and the ⋮ on the row's top line. */
.count-tile {
  display: inline-grid;
  place-items: center;
  width: var(--count-tile);
  height: var(--count-tile);
  min-width: var(--count-tile);
  padding: 0;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: #fff;
  font-size: var(--text);
  font-weight: 400;
  line-height: 1;
}
.chip.priority-chip:has(> .priority-icon) { padding-left: 9px; }

/* ------------------------------------------------------------------ */
/* 8. Lists: a table on a laptop, tiles on a phone                     */
/* ------------------------------------------------------------------ */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 20px;
  white-space: nowrap;
  font-weight: 400;
}
th {
  color: var(--muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}
td { border-top: 1px solid var(--line); }
tbody tr { cursor: pointer; transition: background 140ms ease; }
tbody tr:hover { background: var(--paper-2); }
td .pill { white-space: nowrap; }
/* Actions stick to the table's right edge; the name / subject column takes the leftover width. */
th.col-fill, td.col-fill { width: 100%; min-width: 0; white-space: normal; }
th.col-actions, td.col-actions { width: 1%; white-space: nowrap; text-align: right; vertical-align: middle; }
:is(th, td).col-num { font-variant-numeric: tabular-nums; }
td.col-email { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th.bulk-col, td.bulk-col { width: 24px; padding-right: 0; }
.bulk-col input { margin: 0; cursor: pointer; }
.empty { padding: 24px var(--board-pad-x); color: var(--muted); text-align: center; font-weight: 400; }

/* The name / subject in a row opens the same editor as the pencil. */
button.cell-link,
a.cell-link {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-size: var(--text);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
}
button.cell-link:is(:hover, :focus-visible),
a.cell-link:is(:hover, :focus-visible) { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.row-title { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.cell-company { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); color: var(--muted); }
/* Contacts Phone/Mobile (David, 2026-11-01): no mobile → the company's
   business phone, with a quiet "business" tag so it isn't read as theirs. */
.contact-phone-tag { font-size: var(--text-sm); color: var(--muted); }

/* A person in a row: avatar, name, a line under it. */
.who { display: flex; align-items: center; gap: 10px; }
.who .row-title,
.who-copy { min-width: 8em; overflow-wrap: normal; }
.who-copy { display: grid; gap: 1px; }
.who-sub { color: var(--muted); font-size: var(--text-sm); }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--white);
  font-weight: 400;
  letter-spacing: 0.02em;
  flex: none;
}

/* Laptop widths: tighter cells. */
@media (max-width: 1599px) {
  .table-wrap > table :is(th, td) { padding-inline: 10px; }
  .table-wrap > table :is(th, td):first-child { padding-left: 16px; }
  .table-wrap > table td.col-email { max-width: 160px; }
}
/* Contacts show the whole email (David, 2026-11-01: "space this out in
   contacts so that i can see full email"). From 1280px Email takes up to
   34ch (a typical name@company.com.au) from the name column's spare room;
   only a longer address ends in "…" (full one on hover). Other lists with an
   Email column keep the cap above so they still fit. */
@media (min-width: 1280px) {
  .table-wrap > table[data-list="members"] td.col-email { max-width: 34ch; }
}
/* 701-1279px: cells may wrap between words so every list fits the page. */
@media (min-width: 701px) and (max-width: 1279px) {
  td { white-space: normal; overflow-wrap: normal; }
  :is(th, td).col-fill { width: auto; }
  td:is(.col-mobile, .col-phone, .col-date) { white-space: nowrap; }
  td.col-actions .row-actions { flex-wrap: wrap; width: max-content; max-width: calc(3 * var(--icon-box) + 2 * var(--icon-gap)); margin-left: auto; }
  td.col-actions .row-actions:has(> .btn-icon:nth-child(4):last-child) { max-width: calc(2 * var(--icon-box) + var(--icon-gap)); }
  /* With word buttons the cell is as wide as them, icons wrap underneath. */
  td.col-actions .row-actions:has(> .text-actions) { width: min-content; max-width: none; }
  .table-wrap > table > * > tr > :is(th, td).col-actions { box-shadow: inset 1px 0 0 var(--line); }
}
/* A list that still doesn't fit scrolls sideways under Actions, which stay pinned. */
@media (min-width: 701px) {
  .table-wrap > table > * > tr > :is(th, td).col-actions { position: sticky; right: 0; z-index: 1; }
  .table-wrap > table > tbody > tr > td.col-actions { background: var(--white); }
  .table-wrap > table > tbody > tr:hover > td.col-actions { background: var(--paper-2); }
}

/* Phones: a list table (renderDataTable / ticket groups / contractor lists,
   `table.dt-cards`) shows each row as its own tile: heading first, then
   "Column  value" lines, the action icons top right. */
@media (max-width: 700px) {
  .table-wrap:has(> table.dt-cards) { overflow: visible; }
  table.dt-cards, table.dt-cards > tbody { display: block; width: 100%; min-width: 0; }
  table.dt-cards > thead { display: none; }
  table.dt-cards tr.dt-row,
  table.dt-cards tr.detail-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 12px;
    row-gap: 4px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
  }
  table.dt-cards tr.dt-row.has-detail { border-bottom: 0; padding-bottom: 4px; }
  table.dt-cards tr.detail-row { padding-top: 0; padding-left: var(--board-pad-x); padding-right: var(--board-pad-x); }
  table.dt-cards tr > td {
    display: block;
    grid-column: 2;
    min-width: 0;
    max-width: none;
    width: auto;
    padding: 0 !important;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
  }
  /* Tick box and status icon in their own narrow column beside the card. */
  table.dt-cards tr > td.bulk-col,
  table.dt-cards tr > td.status-col { grid-column: 1; grid-row: 1 / span 2; align-self: start; padding-top: 2px !important; }
  table.dt-cards tr > td.bulk-col + td.status-col { grid-row: 3 / span 2; }
  table.dt-cards tr > td:empty:not(.bulk-col):not(.status-col) { display: none; }
  table.dt-cards td.col-fill { grid-row: 1; font-size: var(--text-md); }
  /* Projects list: company above the project name. */
  table.dt-cards[data-list="projects"] td.col-companyId { grid-row: 1; display: block; color: var(--muted); font-size: var(--text); }
  table.dt-cards[data-list="projects"] td.col-companyId::before { content: none; }
  table.dt-cards[data-list="projects"] td.col-fill { grid-row: 2; }
  table.dt-cards td.col-fill .row-title { white-space: normal; text-align: left; }
  /* On a card the name wraps and its pills drop below it when there is no room. */
  table.dt-cards .who { flex-wrap: wrap; }
  table.dt-cards .who-copy { min-width: 0; }
  table.dt-cards td .cell-clip { white-space: normal; overflow: visible; text-overflow: clip; max-width: none; width: auto; }
  table.dt-cards td[data-label] { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: baseline; font-size: var(--text); }
  table.dt-cards td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: var(--text-sm); }
  table.dt-cards td[data-label] > * { grid-column: 2; min-width: 0; justify-self: start; }
  table.dt-cards td.is-blank { display: none !important; }
  /* An empty Start / Due date cell (an "—" button) is left off the card too. */
  table.dt-cards td[data-label]:has(> .inline-pick.is-empty:only-child) { display: none !important; }
  #list-view table.dt-cards td.col-email, table.dt-cards td.col-email { max-width: none; overflow: visible; text-overflow: clip; white-space: normal; }
  table.dt-cards tr.detail-row .detail-item + .detail-item::before { content: none; }
  table.dt-cards td.col-actions { margin-top: 4px; }
  /* Tickets: the short fields (dates, type, assignee, status, priority) sit
     two to a line, name above value, so a card stays short. */
  table.dt-cards tr.dt-row:has(> td.status-col .status-icon-btn) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); row-gap: 8px; }
  table.dt-cards tr.dt-row:has(> td.status-col .status-icon-btn) > td:not(.status-col) { grid-column: auto; }
  /* The status icon repeats the Status pill (which changes it too). */
  table.dt-cards tr.dt-row > td.status-col:has(.status-icon-btn) { display: none; }
  table.dt-cards tr.dt-row:has(> td.status-col .status-icon-btn) > td:is(.col-fill, .col-actions) { grid-column: 1 / -1; }
  table.dt-cards tr.dt-row:has(> td.status-col .status-icon-btn) > td[data-label] { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  table.dt-cards tr.dt-row:has(> td.status-col .status-icon-btn) > td[data-label] > * { grid-column: 1; }
  /* Two to a line: an empty date keeps its slot (hidden, not removed), so every
     ticket tile has its fields in the same places. */
  table.dt-cards tr.dt-row:has(> td.status-col .status-icon-btn) > td[data-label]:has(> .inline-pick.is-empty:only-child) { display: grid !important; visibility: hidden; }
  table.dt-cards td.col-actions .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  /* Status reads as plain text on a card; still tappable to change it. */
  table.dt-cards td.col-status :is(.inline-pick > .pill, .pill) { background: none; border: 0; box-shadow: none; padding: 0; min-height: 0; height: auto; color: var(--ink); font: inherit; text-transform: none; letter-spacing: normal; }
  /* Contacts: one tile per person. Tick box beside the name, then Email,
     Mobile, Job title, Role and Status as labelled lines, buttons last. */
  table.dt-cards tr.detail-row { display: none !important; }
  table.dt-cards tr.dt-row.has-detail { border-bottom: 1px solid var(--line); padding-bottom: 12px; row-gap: 6px; }
  table.dt-cards tr.dt-row.has-detail > td.bulk-col { grid-row: 1; align-self: center; padding-top: 0 !important; }
  table.dt-cards tr.dt-row.has-detail > td:not(.bulk-col):not(.col-fill) { grid-column: 1 / -1; }
  /* 104px, not 84: "Phone/Mobile" broke as "Phone/Mobil e" (David, 2026-11-01). */
  table.dt-cards tr.dt-row.has-detail > td[data-label] { grid-template-columns: 104px minmax(0, 1fr); }
  table.dt-cards tr.dt-row.has-detail > td.col-actions { margin-top: 6px; }
  table.dt-cards tr.dt-row.has-detail td.col-fill .welcome-pills { margin-left: 8px; }
  table.dt-cards tr.dt-row.has-detail .welcome-state { text-transform: none; font-size: var(--text-sm); padding: 1px 8px; }
  table.dt-cards tr.dt-row:not(:has(> td.bulk-col)):not(:has(> td.status-col)) > td { grid-column: 1 / -1; }

  /* Every list is tiles, like the tickets (David, 2026-10-28: "Separate
     tiles", "Everywhere"): each row its own framed, rounded tile with a gap
     before the next, on the grey page instead of rows split by a line
     inside one big card. */
  table.dt-cards > tbody { display: grid; gap: 10px; }
  table.dt-cards :is(tr.dt-row, tr.dt-row.has-detail) { padding: 14px; background: var(--white); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-sm, none); }
  /* No box inside a box: a card that holds only a list (its count line, bulk
     bar and filters aside) goes and the tiles sit on the page. */
  .board:has(> .table-wrap:not([hidden]) > table.dt-cards):not(:has(> :not(.board-meta, .bulk-bar, .table-wrap, .ticket-groups, .group-tiles, .panel-toolbar, .site-pro-top, .company-admins))) { background: transparent; border: 0; border-radius: 0; box-shadow: none; overflow: visible; }
  .board:has(> .table-wrap:not([hidden]) > table.dt-cards):not(:has(> :not(.board-meta, .bulk-bar, .table-wrap, .ticket-groups, .group-tiles, .panel-toolbar, .site-pro-top, .company-admins))) > .board-meta { padding: 4px 2px 10px; }
  .board:has(> .table-wrap:not([hidden]) > table.dt-cards):not(:has(> :not(.board-meta, .bulk-bar, .table-wrap, .ticket-groups, .group-tiles, .panel-toolbar, .site-pro-top, .company-admins))) > .bulk-bar { padding: 0 2px 10px; }

  /* The action icons top right beside the heading (David, 2026-10-31). They
     share the first row with the heading, which keeps the room they leave
     (--icon-box each, --icon-gap apart) and wraps under them. */
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon) > td.col-actions { grid-row: 1; grid-column: 1 / -1; justify-self: end; align-self: start; width: max-content; margin-top: 0; }
  table.dt-cards tr.dt-row > td.col-actions .row-actions:has(> .btn-icon) { flex-wrap: nowrap; gap: var(--icon-gap); }
  table.dt-cards tr.dt-row > td.col-actions .row-actions > .btn-icon { width: var(--icon-box); height: var(--icon-box); min-height: var(--icon-box); }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon) > td.col-fill,
  table.dt-cards[data-list="projects"] tr.dt-row > td.col-companyId { padding-right: calc(var(--tile-icons, 0) * (var(--icon-box) + var(--icon-gap)) + 8px) !important; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon) > td.col-fill .who > :is(.row-title, .who-copy) { flex: 1 1 0; min-width: 0; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon) > td.col-fill .who > .welcome-pills { flex: 1 0 100%; margin-left: 0; padding-left: 42px; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon:nth-of-type(1)) { --tile-icons: 1; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon:nth-of-type(2)) { --tile-icons: 2; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon:nth-of-type(3)) { --tile-icons: 3; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon:nth-of-type(4)) { --tile-icons: 4; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon:nth-of-type(5)) { --tile-icons: 5; }
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .btn-icon:nth-of-type(6)) { --tile-icons: 6; }
}
table.dt-cards tr[hidden] { display: none !important; }

/* Phone person tiles (contacts, contractors, administrators, a contractor's
   team; any list row whose heading is an avatar + name), David 2026-10-31:
   "Align check box", "This is slop. Looks awful." Tick box, avatar and name
   share the first row, the name on one line (cut with … when long), then the
   company line and welcome pills under the name, then the action icons on a
   row of their own at the right, so five icons never squeeze the name.
   In the style guide, which every panel loads last, so there is one copy.
   Check: scripts/checks/ui-person-tiles.mjs. */
@media (max-width: 700px) {
  table.dt-cards tr.dt-row:has(> td.col-fill .who > .avatar) > td.col-fill { grid-row: 1; padding-right: 0 !important; }
  table.dt-cards tr.dt-row:has(> td.col-fill .who > .avatar) > td.col-actions { grid-row: 2; grid-column: 1 / -1; justify-self: end; align-self: start; width: max-content; margin: 2px 0 4px; }
  /* With word buttons too (company Contractors: Projects, Unassign) the row is
     wider than the tile: it wraps inside it, icons under the words, instead
     of running off the left edge (David, 2026-11-02). */
  table.dt-cards tr.dt-row:has(> td.col-actions .row-actions > .text-actions) > td.col-actions { width: auto; max-width: 100%; }
  table.dt-cards tr.dt-row > td.col-actions .row-actions:has(> .text-actions) { flex-wrap: wrap; justify-content: flex-end; }
  table.dt-cards tr.dt-row:has(> td.col-fill .who > .avatar) > td.bulk-col { grid-row: 1; align-self: start; display: flex; align-items: center; height: 32px; padding-top: 0 !important; }
  table.dt-cards tr.dt-row:has(> td.col-fill .who > .avatar) > td.bulk-col input { margin: 0; }
  table.dt-cards td.col-fill .who:has(> .avatar) { flex-wrap: wrap; align-items: flex-start; column-gap: 10px; row-gap: 4px; }
  table.dt-cards td.col-fill .who:has(> .avatar) > :is(.who-copy, .row-title) { flex: 1 1 0; min-width: 0; }
  table.dt-cards td.col-fill .who:has(> .avatar) .row-title { display: block; max-width: 100%; min-height: 32px; line-height: 32px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
  table.dt-cards td.col-fill .who:has(> .avatar) .who-copy { gap: 4px; }
  table.dt-cards td.col-fill .who:has(> .avatar) .who-sub { margin-top: -6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  table.dt-cards td.col-fill .who:has(> .avatar) .who-copy > .welcome-pills { order: 2; margin-left: 0; padding-left: 0; }
  table.dt-cards td.col-fill .who:has(> .avatar) > .welcome-pills { flex: 1 0 100%; margin: 0; padding-left: 42px; }
  table.dt-cards td.col-fill .who:has(> .avatar) .welcome-pills { display: flex; flex-wrap: wrap; gap: 6px; }
  table.dt-cards td.col-fill .who:has(> .avatar) .welcome-pills .welcome-state { margin: 0; }
}

/* ------------------------------------------------------------------ */
/* 8b. Grouped lists                                                   */
/* ------------------------------------------------------------------ */
/* Each group its own rounded tile (David, 2026-11-01: Contacts by company
   "wrong", "like this one" = Tickets by company). One builder,
   public/group-tile.js: Tickets by company, Contacts by company and the
   contractor / contact ticket groups all use it. Caret, name, count pill,
   buttons on the right; the group's list opens inside the tile. A new
   grouped list uses it too, never heading rows inside a table.
   Check: scripts/checks/ui-contact-groups.mjs. */
.group-tiles { display: grid; gap: var(--space-2); padding: 0 var(--space-3) var(--space-3); }
.group-tiles > * { min-width: 0; }
.group-tile {
  border: 1px solid var(--line);
  /* A box inside a card takes the smaller radius, like the other nested boxes. */
  border-radius: var(--radius-sm);
  background: var(--white);
  padding: 0 var(--space-3);
  min-width: 0;
}
.group-tile-bar { display: flex; align-items: center; gap: var(--space-2); }
.group-tile-head {
  appearance: none;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: none;
  padding: 12px 0;
  font: inherit;
  font-size: var(--text);
  font-weight: 400;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.group-tile-head:hover .ticket-group-count { color: var(--ink); }
.group-tile-name { font-size: var(--text); font-weight: 600; line-height: 1.3; min-width: 0; overflow-wrap: anywhere; }
.group-tile-body { padding: 0 0 var(--space-2); min-width: 0; }
.group-tile-body .ticket-group-body { padding-left: 0; }
.group-tile.is-dragging { opacity: 0.5; }
.group-tile-bar .group-toggle { margin-left: auto; }
/* A grouped list's count row: A–Z / Z–A and Expand / Collapse on the right,
   side by side (admin and contractor lists). */
.board-meta .group-toggle { margin-left: auto; }
.board-meta .company-sort + .group-toggle { margin-left: var(--space-1); }
/* Small icon buttons on the right of the bar (drag grip, open company). */
.group-tile-grip,
.group-tile-link {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin-left: auto;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
}
.group-tile-grip { cursor: grab; }
.group-tile-grip:active { cursor: grabbing; }
.group-tile-grip:hover, .group-tile-link:hover { background: var(--paper); color: var(--ink); }
.group-tile-grip svg, .group-tile-link svg { width: 16px; height: 16px; }
/* The list inside a tile gets a thin frame, like a ticket group's table. */
.group-tile-body > .table-wrap.group-tile-table { border: 1px solid var(--line); border-radius: var(--radius-control); }
/* Count pill beside a group name (tiles and ticket status sections). */
.ticket-group-count { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px; background: var(--paper, #f3f4f6); color: var(--muted); font-size: var(--text-sm); line-height: 1; font-variant-numeric: tabular-nums; }
/* Same chevron as the side menu: 12 x 8, points down when closed, up when open. */
.group-caret { width: 12px; height: 8px; flex: 0 0 auto; color: var(--muted); transition: transform 140ms ease; transform: rotate(180deg); }
.group-tile.is-collapsed > .group-tile-bar .group-caret { transform: none; }
@media (max-width: 700px) {
  .group-tiles { padding: 0; gap: 10px; }
  .group-tile { padding: 0 14px; border-radius: 10px; box-shadow: var(--shadow-sm, none); }
  /* No box in a box: the people inside an open tile are lines, not tiles. */
  .group-tile-body > .table-wrap.group-tile-table { border: 0; border-radius: 0; }
  .group-tile-table table.dt-cards > tbody { gap: 0; }
  .group-tile-table table.dt-cards :is(tr.dt-row, tr.dt-row.has-detail) { background: transparent; border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; padding: 12px 0; }
}

/* 9. Dialogs                                                          */
/* ------------------------------------------------------------------ */
.confirm-dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: 460px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.confirm-dialog::backdrop { background: rgba(15, 23, 42, .35); }
.confirm-dialog form { display: grid; gap: 14px; padding: 22px 24px; }
.confirm-dialog h2 { margin: 0; font-size: var(--heading); font-weight: 500; text-align: left; }
.confirm-dialog p { margin: 0; line-height: 1.5; }
.confirm-dialog .confirm-actions .btn { width: auto; }
.confirm-dialog .status:empty { display: none; }
.confirm-choice { display: grid; gap: 8px; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.confirm-choice legend { padding: 0 4px; color: var(--muted); }
@media (max-width: 560px) {
  .confirm-dialog form { padding: 18px 16px; }
}

/* ------------------------------------------------------------------ */
/* 10. Small shared things                                             */
/* ------------------------------------------------------------------ */
/* The hidden attribute always wins over a component's display rule. */
[hidden] { display: none !important; }
.hidden { display: none !important; }

/* Every collapsible section uses the sidebar's chevron: thin grey line,
   down when closed, up when open. */
details > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  cursor: pointer;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::after {
  content: "";
  flex: none;
  width: 12px;
  height: 8px;
  background: #666;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='black' stroke-width='1.4'%3E%3Cpath d='M1.5 1.5L6 6 10.5 1.5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='black' stroke-width='1.4'%3E%3Cpath d='M1.5 1.5L6 6 10.5 1.5'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform 140ms ease;
}
details[open] > summary::after { transform: rotate(180deg); }

/* Search boxes: the clear (x) shows whenever there's text. */
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  margin-left: 6px;
  cursor: pointer;
  opacity: 1;
  pointer-events: auto;
  background: #666;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M2 2l8 8M10 2l-8 8'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M2 2l8 8M10 2l-8 8'/%3E%3C/svg%3E") center / contain no-repeat;
}
input[type="search"]::-webkit-search-cancel-button:hover { background: var(--ink, #1b1b1b); }

/* Autosave: "Auto Saved.." is green and bold; errors stay red. */
.status.is-saved { color: var(--success, #2e7d32); font-weight: 700; }

/* Save at the right of a page's tabs row (admin contractor page, company
   Details; David 2026-11-01): "Auto Saved.." sits just left of Save in the
   same row, so neither pushes the form down. Its room is kept free all the
   time (padding on the bar), so the tabs never move or get covered when it
   shows or clears. */
.tabs-save { --save-status-w: 92px; position: relative; display: flex; align-items: center; flex: none; margin-left: auto; padding-left: calc(var(--save-status-w) + var(--space-2, 8px)); }
.tabs-save > .status.autosave-beside { position: absolute; left: 0; width: var(--save-status-w); top: 50%; transform: translateY(-50%); margin: 0; text-align: right; white-space: nowrap; font-size: var(--text-sm); }
.tabs-row:has(> .tabs-save:not([hidden])) { flex-wrap: nowrap; }
.tabs-row:has(> .tabs-save:not([hidden])) > .tabs { min-width: 0; }
/* Phones: no room on the row for both, so the room isn't kept and
   "Auto Saved.." shows just above Save, right-aligned, in the gap over the
   tabs (still out of the flow: nothing moves). */
@media (max-width: 700px) {
  .tabs-save { padding-left: 0; }
  .tabs-save > .status.autosave-beside { left: auto; right: 0; width: auto; top: auto; bottom: calc(100% + 2px); transform: none; font-size: var(--text-sm); line-height: 1.2; }
}

/* ------------------------------------------------------------------ */
/* Chat dark mode                                                      */
/* ------------------------------------------------------------------ */
/* The Moon / Sun button at the top right of every chat header turns that
   person's chats dark (David, 2026-11-04: "toggle between the current light
   mode for chat and dark mode", one choice for all chats, saved per person;
   /chat-theme.js). Only the chat window changes: the tile heading around it
   and the rest of the page stay light. The guide's tokens are redefined
   inside the window, so every rule that already uses them follows; the few
   rules below cover the literal whites. Counts stay readable because they are
   --accent fills with --white words, and both swap together; the green
   New / Create buttons keep --create with white words. */
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark {
  --ink: #e6e9ed;
  --ink-soft: #c7cdd4;
  --paper: #0f1419;
  --paper-2: #1b232b;
  --fill: #26313b;
  --white: #161d24;
  --bg: #161d24;
  --muted: #9ba6b2;
  --line: #303c47;
  --accent: #6bb7e3;
  --accent-soft: #1c3546;
  --accent-hover: #8ccbef;
  --link: #8cc8ec;
  --live-soft: #1b3321;
  --success: #6cc678;
  --warn-soft: #3a2e12;
  --warn-ink: #f2b75e;
  --danger-soft: #3d1b1b;
  --danger-ink: #ff8f85;
  --hold-soft: #3a352b;
  --ai: #b69bff;
  --control-bg: #1b232b;
  --control-focus-border: #e6e9ed;
  --shadow: none;
  --shadow-sm: none;
  --chat-pane: #11171d;
  --chat-mine: #1f4a2b;
  --chat-theirs: #1e272f;
  --chat-bubble-line: #3a4753;
  --chat-link: #8cc8ec;
  color: var(--ink);
  background: var(--white);
  color-scheme: dark;
}
/* Literal whites in the shared button and field rules. */
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark :is(.icon-box.icon-box, .btn-icon.icon-box):not(.close-solid) { background: var(--white); }
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark :is(.icon-box.icon-box, .btn-icon.icon-box):not(.close-solid):hover:not(:disabled) { background: var(--fill); }
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark :is(input:not([type="checkbox"], [type="radio"]), textarea, select, [contenteditable="true"]) {
  background-color: var(--control-bg);
  color: var(--ink);
  border-color: var(--line);
}
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark :is(input, textarea)::placeholder { color: var(--muted); }
@media (max-width: 760px) {
  :is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark .btn.btn.btn.icon-box-phone:not(.btn-primary) { background: var(--white) !important; }
}
/* The message box's formatting bar (Quill draws its icons in a fixed grey). */
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark .ql-snow :is(.ql-stroke, .ql-stroke-miter) { stroke: var(--ink); }
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark .ql-snow :is(.ql-fill, .ql-stroke.ql-fill) { fill: var(--ink); }
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark .ql-snow :is(.ql-picker, .ql-picker-label) { color: var(--ink); }
:is(.chat-window, .ichat, .chat-ctx, .emoji-pop, .icon-tip).chat-dark .ql-snow .ql-picker-options { background: var(--paper-2); border-color: var(--line); }
/* The theme button: an icon box like Call and Video, last on the header row.
   Phones show it at the end of the chat list's top row instead, so the
   header keeps its room for the name; a contact's single chat has no list
   and keeps it in the header. */
.chat-theme-btn.chat-theme-btn { margin-left: var(--icon-gap); }
.chat-theme-list.chat-theme-list { display: none; }
@media (max-width: 760px) {
  .chat-theme-list.chat-theme-list { display: inline-grid; margin-left: auto; }
  :is(.chat-window:not(.is-simple), .ichat) .chat-theme-head.chat-theme-head { display: none; }
}

/* Pop-ups opened from a dark chat (⋮ menu, emoji picker, hover tips) sit
   outside the chat window, so they carry .chat-dark themselves. A tip is a
   raised dark box there, not the light-mode ink box turned inside out. */
.icon-tip.chat-dark { background: var(--paper-2); color: var(--ink); border: 1px solid var(--line); }
.chat-ctx.chat-dark button { color: var(--ink); }

/* User content wraps: nothing anyone types or pastes scrolls sideways
   (David, 2026-11-13: "for the 5th time, horizontal scrolling is no good"; a
   pasted SSH key in a ticket comment gave the Comments list a side scroll bar).
   One long word, link, key, inline code, <pre> or code block, or pasted table
   used to set the width of its card: a card in a grid or flex list is as wide
   as its longest word unless told otherwise, so the scrolling list around it
   grew a side scroll bar (or the page did, in the contractor and client
   panels). Every panel, laptop and phone. A new box that shows what people
   wrote joins the first list; scripts/checks/ui-no-side-scroll.mjs puts long
   unbroken text into tickets, comments, notes and every chat and fails on any
   box that then scrolls sideways or cuts it off. */
body { overflow-wrap: break-word; }
:is(.rich-text, .chat-rich, .chat-line, .ichat-bubble, .ichat-body, .msg-quote-text, .comment-card, .comment-body,
  .feed-card, .note-body, .note-card, .ticket-detail-text, .ctv-description, .resource-body, .issue-body, .ql-editor) {
  min-width: 0; overflow-wrap: anywhere;
}
:is(.rich-text, .chat-rich, .chat-line, .ichat-bubble, .comment-body, .note-body, .ticket-detail-text, .ql-editor) :is(a, code, span, td, th, li) {
  overflow-wrap: anywhere;
}
:is(.rich-text, .chat-rich, .chat-line, .ichat-bubble, .comment-body, .note-body, .ticket-detail-text, .ql-editor) :is(pre, .ql-code-block-container, .ql-code-block, code) {
  max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere;
}
:is(.rich-text, .chat-rich, .chat-line, .ichat-bubble, .comment-body, .note-body, .ticket-detail-text) :is(img, video, iframe, table) {
  max-width: 100%;
}
/* List cells don't wrap (style guide, tables above); a table someone pasted does. */
:is(.rich-text, .chat-rich, .chat-line, .ichat-bubble, .comment-body, .note-body, .ticket-detail-text) :is(td, th) { white-space: normal; }
:is(.rich-text, .chat-rich, .chat-line, .ichat-bubble, .comment-body, .note-body, .ticket-detail-text) img { height: auto; }
