/* The one task card — Tasks spec T2.
 *
 * 🪤 EVERY SELECTOR IS `.cft-` PREFIXED, with no exceptions.
 * styles.css and portal-mobile.css BOTH define a bare `.task-row`, with
 * different padding and borders, and whichever loads last wins. This card is
 * loaded into app.html today and portal.html later, so an unprefixed rule here
 * would silently restyle a shipped screen on one of them.
 *
 * Inherits the host's tokens (--card, --line, --ink, --ink-soft, --brand) so it
 * looks native wherever it is mounted rather than like a widget dropped in.
 */

.cft {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--card, #fff);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
}

.cft-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.cft-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink, #0f172a);
}

/* Glyph AND word, never colour alone — Allan is colourblind. */
.cft-done {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: #dcfce7;
  color: #166534;
}

.cft-block { display: grid; gap: 6px; }

.cft-lbl {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--ink-soft, #64748b);
}

.cft-req { color: #b91c1c; }

.cft-input,
.cft-sel {
  width: 100%;
  min-height: 44px;            /* pointer floor; the touch floor is 48 and set by the host */
  padding: 9px 10px;
  font: inherit;
  color: var(--ink, #0f172a);
  background: #fff;
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 8px;
}

.cft-input:focus,
.cft-sel:focus {
  outline: 2px solid var(--brand, #006aac);
  outline-offset: 1px;
}

.cft-area { min-height: 76px; resize: vertical; }

/* ── Description: rich text ───────────────────────────────────────────────
   Allan: "Cant we show rich text?" — a task body IS HTML (GHL wraps nearly
   every one in a styled <p>), and a <textarea> could only print the tags.

   The toolbar is exactly the tag set CFNoteHtml.renderNoteBody() allows, so
   nothing you can type here is stripped on the way back out. */
.cft-rt {
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 8px;
  overflow: hidden;                      /* keep the bar's corners inside */
  background: #fff;
}
.cft-rt:focus-within { outline: 2px solid var(--brand, #006aac); outline-offset: 1px; }

.cft-rt-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px 6px;
  background: #f6f8fa;
  border-bottom: 1px solid var(--line, #cbd5e1);
}
.cft-rt-btn {
  min-width: 34px;
  min-height: 34px;
  padding: 4px 9px;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  color: var(--ink-soft, #555c66);
  background: #fff;
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 6px;
  cursor: pointer;
}
.cft-rt-btn:hover { background: #eef2f7; }
/* ON is a filled brand button, not a tint — Allan is colourblind, so the state
   carries on WEIGHT and FILL as well as hue, and aria-pressed carries it for a
   screen reader. */
.cft-rt-btn.is-on {
  background: var(--brand, #006aac);
  border-color: var(--brand, #006aac);
  color: #fff;
  font-weight: 700;
}
.cft-rt-btn.is-b { font-weight: 700; }
.cft-rt-btn.is-i { font-style: italic; }
.cft-rt-btn.is-u { text-decoration: underline; }
/* A thumb needs more than a mouse does. 44 is the floor everywhere else in
   the portal; the bar grows to match rather than the buttons staying dainty. */
@media (pointer: coarse) {
  .cft-rt-btn { min-width: 44px; min-height: 44px; font-size: 14px; }
}

/* The editable box itself. Border lives on .cft-rt so the bar and the box read
   as one control, so this one has none of its own. */
.cft-rt-box {
  border: 0;
  border-radius: 0;
  resize: none;
  overflow-y: auto;
  max-height: 260px;
  white-space: normal;                   /* breaks are <br>, not newlines */
  overflow-wrap: anywhere;
}
.cft-rt-box:focus { outline: none; }     /* the ring is on .cft-rt */
/* contenteditable ignores `placeholder`, so the hint is drawn here. :empty
   alone is not enough — a box the user cleared holds a stray <br>. */
.cft-rt-box:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-soft, #8a94a0);
  pointer-events: none;
}
.cft-rt-box ul,
.cft-rt-box ol,
.cft-body--rich ul,
.cft-body--rich ol { margin: 6px 0; padding-left: 22px; }
.cft-rt-box li,
.cft-body--rich li { margin: 2px 0; }
.cft-rt-box a,
.cft-body--rich a { color: var(--brand, #006aac); }

.cft-body--rich { white-space: normal; }

/* ── When ─────────────────────────────────────────────────────────────── */
/* AMBER, like the Diary Task Modal's .t-when — same colours, same weight, same
   two buttons. Allan: "Look the same on Diary and Business Portals." A grey
   strip here was one of the things that made the two screens read as different
   products. */
.cft-when {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 44px;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 700;
  color: #78350f;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 7px;
}

.cft-when__btns { display: flex; gap: 6px; }
.cft-when__btns .cft-mini { font-weight: 700; }

/* Overdue: glyph, word AND a heavier left bar on top of the amber. Never
   colour on its own. */
.cft-when--late {
  border-left: 4px solid #b91c1c;
  background: #fee2e2;
  border-color: #fca5a5;
  color: #7f1d1d;
}

/* ── Segmented controls ───────────────────────────────────────────────── */
/* The Scheduler's .statusseg and .seg, matched exactly: white pills that fill
   GHL blue when live. Progress, and Fixed-or-flexible, are the same control in
   both products because they are the same question. */
.cft-seg { display: flex; flex-wrap: wrap; gap: 6px; }

.cft-seg__b {
  min-height: 44px;
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  cursor: pointer;
}

.cft-seg__b.is-on {
  background: var(--brand, #006aac);
  border-color: var(--brand, #006aac);
  color: #fff;
}

.cft-seg__b:disabled { opacity: .45; cursor: not-allowed; }

/* Looks unavailable, but is still tappable — so it can SAY why on a phone,
   where there is no hover and a disabled button is silence. */
.cft-seg__b.is-unavailable { opacity: .5; }

/* Progress answers directly under its own buttons. The card's shared message
   line is at the foot, past the contact strip — far enough from what you
   tapped that the reply reads as unrelated, and on a phone it can be off
   screen entirely. */
.cft-segmsg { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft, #64748b); }
.cft-segmsg.is-err { color: #b45309; font-weight: 600; }
.cft-seg--big .cft-seg__b { flex: 1 1 0; font-size: 14px; font-weight: 700; }

/* ── Time on site ─────────────────────────────────────────────────────── */
.cft-tos { display: grid; gap: 4px; }

.cft-tos__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
}

.cft-tos__k { font-size: 13px; font-weight: 600; color: var(--ink, #0f172a); }
.cft-tos__v { font-size: 13px; font-weight: 700; color: var(--ink, #0f172a); }
.cft-tos__v.is-none { font-weight: 400; color: var(--ink-soft, #94a3b8); }

/* The green one, like the modal's. It is the button somebody hits standing on
   a doorstep, so it is the biggest thing on the card. */
.cft-bigbtn {
  width: 100%;
  min-height: 48px;
  margin-top: 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: #15803d;
  border: 1px solid #15803d;
  border-radius: 8px;
  cursor: pointer;
}

.cft-bigbtn:hover { background: #166534; }

/* ── Putting a task on the diary ──────────────────────────────────────── */
.cft-place__row { display: flex; gap: 8px; flex-wrap: wrap; }
.cft-sel--n { width: auto; flex: 0 0 auto; min-width: 100px; }

.cft-place__go {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 6px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--brand, #006aac);
  border: 1px solid var(--brand, #006aac);
  border-radius: 8px;
  cursor: pointer;
}

.cft-timeedit {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 🪤 AN EXPLICIT `display` BEATS THE `hidden` ATTRIBUTE.
   The UA stylesheet's [hidden] { display: none } is the WEAKEST rule there is,
   so `display: flex` above silently defeated it and both the time editor and
   the client search rendered open on every card. Caught in a screenshot, not
   by the assertions — which had checked that the elements existed, never that
   they were collapsed. Anything here that toggles with `hidden` needs this. */
.cft-timeedit[hidden],
.cft-search[hidden],
.cft [hidden] { display: none; }

/* 🔴 DATE, HOUR AND MINUTE ON ONE LINE. Allan, from a phone: "can we make the
   date and time on the same line please" — the minute select was wrapping onto
   a row of its own, which reads as a separate field rather than part of a time.
   The date input was `flex: 1 1 150px` and greedy; on a 318px card that left
   nothing for the second select. It shrinks now, and `min-width: 0` is the
   part that actually lets it — a flex item will not go below its intrinsic
   content width without it, and a date input's is wide. */
.cft-timeedit { flex-wrap: nowrap; }
.cft-date { flex: 1 1 auto; width: auto; min-width: 0; }
.cft-timeedit .cft-sel { width: auto; flex: 0 0 auto; min-width: 64px; padding-inline: 6px; }
.cft-colon { font-weight: 700; color: var(--ink-soft, #64748b); }

/* 🪤 44px, NOT 36. These were secondary controls on a wide detail pane and it
   did not matter; the same card is now in a van, where Edit ✎, Pick on diary
   and Save notes are all thumb targets. The Diary Task Modal's .t-mini has
   always been 44 — matching it was the fix. Caught by measuring at 390px, not
   by looking at it. */
.cft-mini {
  flex: none;
  min-height: 44px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand, #006aac);
  background: #fff;
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 8px;
  cursor: pointer;
}

.cft-mini:hover { background: var(--surface, #f8fafc); }
.cft-mini:disabled { opacity: .5; cursor: not-allowed; }

/* ── For / the three contact states ───────────────────────────────────── */
.cft-for {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 44px;
  padding: 8px 10px;
  background: var(--surface, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
}

.cft-for-name { font-weight: 600; color: var(--ink, #0f172a); }

/* The house contact is plumbing, not a person: it never shows a client name
   and never offers to open a record. */
.cft-internal { font-weight: 600; color: var(--ink-soft, #64748b); }

.cft-hint { font-size: 12px; color: var(--ink-soft, #64748b); }

.cft-search { display: grid; gap: 6px; }
.cft-results { display: grid; gap: 4px; max-height: 220px; overflow-y: auto; }

.cft-hit {
  display: grid;
  gap: 1px;
  min-height: 44px;
  padding: 7px 10px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  cursor: pointer;
}

.cft-hit:hover { background: var(--surface, #f8fafc); }
.cft-hit__name { font-weight: 600; color: var(--ink, #0f172a); }
.cft-hit__sub { font-size: 12px; color: var(--ink-soft, #64748b); }

/* An orphan is a dead end and must look like one — a real limit, not a
   styling choice. */
.cft-block--dead { margin: 0; }

.cft-dead {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  color: #7c2d12;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-left: 3px solid #ea580c;   /* shape as well as colour */
  border-radius: 8px;
}

/* The old "On the diary" box lived here — a bordered container holding Length,
   Fixed/flexible, Marker and Progress, greyed when the task had no bar. It is
   gone. The Diary Task Modal has no such thing, so it made the two screens read
   as different products, which is the one thing this exercise exists to stop.
   Those fields now sit in the modal's own positions, and a task without a bar
   simply does not render them. */

.cft-note { margin: 0; font-size: 13px; color: var(--ink-soft, #64748b); }
.cft-note--on { font-weight: 600; color: var(--ink, #0f172a); }
.cft-mini--go { justify-self: start; }

/* ── Body, messages, actions ──────────────────────────────────────────── */
.cft-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink, #0f172a);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.cft-err,
.cft-msg { margin: 0; font-size: 13px; }
.cft-err { color: #b91c1c; font-weight: 600; }
.cft-msg { color: var(--ink-soft, #64748b); }

/* ── The contact strip (T5) ───────────────────────────────────────────── */
/* What you DO once you have read the task, at the foot of the card. Set off
   from the fields above by a rule rather than a box — it is not another field,
   and another bordered container is what made the diary block feel foreign. */
.cft-who {
  display: grid;
  gap: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line, #e2e8f0);
}

.cft-who__name {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink, #0f172a);
}

/* Each line is a button, because each line copies. */
.cft-who__line {
  display: grid;
  grid-template-columns: 20px 1fr 18px;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 34px;
  padding: 4px 6px;
  margin-left: -6px;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  color: var(--ink, #0f172a);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.cft-who__line:hover { background: var(--surface, #f8fafc); }
.cft-who__line.is-copied { background: #dcfce7; }
.cft-who__g { font-size: 13px; }
.cft-who__v { overflow-wrap: anywhere; }

.cft-who__copy {
  font-size: 12px;
  color: var(--ink-soft, #94a3b8);
  text-align: right;
}

.cft-who__acts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* The tel:/mailto: ones are anchors, so they need the button's own metrics
   back — an <a> has no min-height and does not centre its own text. */
.cft-who__acts .cft-mini {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.cft-acts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

.cft-acts .btn { min-height: 44px; }

/* ── On a touch screen ────────────────────────────────────────────────── */
/* The pointer floor is 44; the TOUCH floor on this fleet is 48, enforced by
   npm run check:touch. `pointer: coarse` is the honest test — it is a phone or
   a tablet, not a window someone happened to make narrow. One rule covers both
   surfaces, so the phone cannot drift from the desk. */
@media (pointer: coarse) {
  .cft-input,
  .cft-sel,
  .cft-mini,
  .cft-seg__b,
  .cft-place__go,
  .cft-acts .btn { min-height: 48px; }
  .cft-who__line { min-height: 44px; }

  /* 🔴 RECLAIM THE WIDTH. On a phone this card sits inside FOUR other padded
     containers — portal-wrap 16, portal-panel 12, task-row 14, the row's
     expand — so its own 16 was the fifth. Every pixel of it is width the
     content does not get, and on a 390px screen that is what pushed Progress
     onto two lines. The desk keeps 16; a phone has no room to spare. */
  .cft { padding: 12px 10px; gap: 12px; }

  /* Three segments have to fit one line at 390px. Tighter padding buys ~24px,
     and letting them shrink means the longest word decides the width rather
     than the widest button. */
  .cft-seg__b { padding: 5px 8px; flex: 0 1 auto; min-width: 0; }
  .cft-seg--big .cft-seg__b { padding: 5px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .cft-mini, .cft-hit { transition: none; }
}
