/* ─────────────────────────────────────────────────────────────────────────
   APPLY TEMPLATE — preview it, trim it, then apply it.
   The preview reads as the plan it will build: numbered stage bands, work
   stream cards, deliverable cards, task rows. Deleted rows stay on the page
   struck through, because a delete you can't see is a delete you can't undo.
   See apps/Work/work-template-compose.js for the why.
   ───────────────────────────────────────────────────────────────────────── */

.wkc { position: fixed; inset: 0; z-index: 2000050; display: none; align-items: center; justify-content: center; }
.wkc.is-open { display: flex; }
.wkc [hidden] { display: none !important; }
.wkc-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .58); }

.wkc-card {
  position: relative;
  width: min(880px, 94vw);
  height: 90vh;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .34);
  display: flex;
  flex-direction: column;
  animation: wkc-popin .2s cubic-bezier(.2, .8, .2, 1);
}
@keyframes wkc-popin { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }

/* ── Head ─────────────────────────────────────────────────────────────── */
.wkc-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid #eef2f7; flex-shrink: 0; }
.wkc-head-titles { flex: 1; min-width: 0; }
.wkc-title { font-weight: 800; font-size: 16.5px; color: #0f172a; letter-spacing: -.01em; }
.wkc-sub { font-size: 12.5px; color: #64748b; margin-top: 2px; }
.wkc-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px 6px 8px; border: 1px solid #e2e8f0; border-radius: 8px;
  background: #fff; color: #475569; cursor: pointer;
  font-size: 12.5px; font-weight: 600; flex-shrink: 0;
}
.wkc-back:hover { background: #f8fafc; color: #0f172a; }
.wkc-restore-all {
  padding: 6px 11px; border: 1px solid #e2e8f0; border-radius: 8px;
  background: #fff; color: #b45309; cursor: pointer;
  font-size: 12px; font-weight: 700; flex-shrink: 0; white-space: nowrap;
}
.wkc-restore-all:hover { background: #fffbeb; border-color: #fcd34d; }
.wkc-close {
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent;
  color: #64748b; cursor: pointer; font-size: 22px; line-height: 1; flex-shrink: 0;
}
.wkc-close:hover { background: #f1f5f9; color: #0f172a; }

.wkc-body { flex: 1; min-height: 0; overflow: auto; padding: 16px 18px 30px; background: #fafbfc; }

/* ── Foot ─────────────────────────────────────────────────────────────── */
.wkc-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 18px; border-top: 1px solid #e5e7eb; background: #fff; flex-shrink: 0;
}
.wkc-foot-left { min-width: 0; }
.wkc-meta { font-size: 12.5px; color: #475569; }
.wkc-meta strong { color: #0f172a; font-weight: 800; }
.wkc-meta-target { color: #4f46e5; font-weight: 700; }
.wkc-meta-note { color: #94a3b8; font-weight: 600; margin-left: 8px; }
.wkc-status { font-size: 11.5px; color: #94a3b8; margin-top: 2px; min-height: 14px; }
.wkc-foot-acts { display: flex; gap: 8px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════════════════════════
   THE PREVIEW TREE
   ══════════════════════════════════════════════════════════════════════ */
.wkp-tree { display: flex; flex-direction: column; gap: 10px; }

.wkp-node { border-radius: 11px; position: relative; }
.wkp-head { display: flex; align-items: flex-start; gap: 9px; padding: 9px 11px; position: relative; }
.wkp-rail {
  position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--wkp-c, #94a3b8);
}
.wkp-titles { flex: 1; min-width: 0; }
.wkp-tier {
  display: block; font-size: 9.5px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--wkp-c, #94a3b8); opacity: .85; margin-bottom: 1px;
}
.wkp-body { padding: 0 9px 9px 20px; display: flex; flex-direction: column; gap: 6px; }

/* Tier treatments — a stage band, a work stream card, a deliverable card,
   a task row. The same visual ladder the live plan uses. */
.wkp-node--stage { background: #f0fdfa; border: 1px solid #ccfbf1; }
.wkp-node--stage > .wkp-head { padding: 11px 12px; }
.wkp-node--project { background: #fff; border: 1px solid #e5e7eb; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); }
.wkp-node--deliverable { background: #fdfcff; border: 1px solid #ede9fe; }
.wkp-node--task { background: #fff; border: 1px solid #f1f5f9; }
.wkp-node--milestone { background: #f0f9ff; border: 1px solid #e0f2fe; }

.wkp-seq {
  flex-shrink: 0; width: 21px; height: 21px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #0f766e; color: #fff; font-size: 11.5px; font-weight: 800; margin-top: 8px;
}

/* Editable name — reads as text until you go near it. */
.wkp-name {
  display: block; width: 100%;
  padding: 3px 6px; margin-left: -6px;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
  color: #0f172a; font-size: 13.5px; font-weight: 650;
  font-family: inherit; line-height: 1.35;
}
.wkp-node--stage > .wkp-head .wkp-name { font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
.wkp-node--project > .wkp-head .wkp-name { font-size: 14.5px; font-weight: 750; }
.wkp-node--task > .wkp-head .wkp-name { font-weight: 550; }
.wkp-name:hover:not(:disabled) { border-color: #e2e8f0; background: #fff; }
.wkp-name:focus { outline: none; border-color: #4f46e5; background: #fff; box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
.wkp-name:disabled { cursor: default; }

.wkp-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.wkp-chip {
  font-size: 10.5px; font-weight: 650; line-height: 1;
  padding: 3px 6px; border-radius: 5px;
  background: #f1f5f9; color: #64748b;
}
.wkp-chip--pri { background: #fef3c7; color: #92400e; text-transform: capitalize; }
.wkp-chip--own { background: #eef2ff; color: #4338ca; }
.wkp-chip--flag { background: #fee2e2; color: #b91c1c; }
.wkp-notes {
  font-size: 11.5px; color: #94a3b8; margin-top: 4px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* Row action — hidden until the row is under the pointer, so a page of
   plan doesn't read as a page of buttons. */
.wkp-act {
  flex-shrink: 0; width: 24px; height: 24px; margin-top: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #e2e8f0; border-radius: 6px; background: #fff;
  color: #94a3b8; cursor: pointer; opacity: 0; transition: opacity .12s;
}
.wkp-node:hover > .wkp-head > .wkp-act,
.wkp-act:focus-visible { opacity: 1; }
.wkp-act--rm:hover { background: #fee2e2; border-color: #fecaca; color: #b91c1c; }
.wkp-act--undo { opacity: 1; color: #b45309; border-color: #fcd34d; background: #fffbeb; }
.wkp-act--undo:hover { background: #fef3c7; }

/* Deleted — still on the page, still reversible. */
.wkp-node.is-removed { opacity: .55; }
.wkp-node.is-removed > .wkp-head > .wkp-titles > .wkp-name { text-decoration: line-through; color: #94a3b8; }
.wkp-node.is-removed > .wkp-head > .wkp-rail { background: #cbd5e1; }
.wkp-node.is-removed-by-parent { opacity: 1; }   /* the parent already dimmed it */
.wkp-node.is-removed .wkp-chips,
.wkp-node.is-removed .wkp-notes { opacity: .7; }

.wkp-blank { padding: 40px 18px; text-align: center; }
.wkp-blank-title { font-size: 14px; font-weight: 750; color: #334155; }
.wkp-blank-sub { font-size: 12.5px; color: #94a3b8; margin-top: 5px; }

@media (max-width: 640px) {
  .wkc-card { width: 96vw; height: 94vh; }
  .wkc-head { flex-wrap: wrap; }
  .wkp-body { padding-left: 12px; }
}
