/* =========================================================================
   PLAN / RETAINER — the Deliverables-tab plan rail (admin), the Manage-services
   library drawer, the per-client plan sheet, and the client-portal "My Plan"
   page. Shared building blocks (.plan-ring / .plan-item / .plan-tl) are used by
   both apps via src/features/clients/planShared.js.
   ========================================================================= */

/* ---- admin: Deliverables full-bleed two-column layout ------------------
   The tab fills the whole page (same full-bleed treatment as the Content
   tab): the deliverables list centers in the flexible left column and the
   plan rail pins to the right edge behind a FULL-HEIGHT divider. */
.client-detail:has(#cdDeliverablesSlot) { display: flex; flex-direction: column; min-height: 100%; padding: 0; }
.client-detail:has(#cdDeliverablesSlot) .cd-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#cdDeliverablesSlot { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cdeliv-layout { flex: 1; display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 4fr); align-items: stretch; }
/* fill the left column edge-to-edge (like every other tab) — override the
   standalone .cdeliv-page 760px centering cap */
.cdeliv-layout .cdeliv-page { width: 100%; max-width: none; margin: 0; }
.cdeliv-rail { display: flex; flex-direction: column; gap: var(--space-5); padding: var(--space-6); min-width: 0; border-left: 1px solid var(--border); }
@media (max-width: 1080px) {
  .cdeliv-layout { display: flex; flex-direction: column; }
  .cdeliv-rail { border-left: 0; border-top: 1px solid var(--border); padding: var(--space-5) var(--space-6) var(--space-6); }
}

/* ---- plan card (admin rail) -------------------------------------------- */
.plan-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.plan-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.plan-card-title { font-size: var(--text-md); font-weight: var(--fw-bold); color: var(--text-strong); margin: 0; }
.plan-chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--primary-600); background: var(--primary-50); white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.plan-hero { display: flex; align-items: center; gap: var(--space-4); }
.plan-hero-cycle { min-width: 0; }
.plan-hero-cycle .plan-cycle { display: block; font-size: var(--text-md); font-weight: var(--fw-bold); color: var(--text-strong); }
.plan-hero-cycle .plan-billing { display: block; font-size: var(--text-sm); color: var(--text-soft); margin-top: 2px; }

/* ring */
.plan-ring { position: relative; flex: 0 0 auto; }
.plan-ring svg { width: 100%; height: 100%; display: block; }
.plan-ring-track { stroke: var(--border); }
.plan-ring-fill { stroke: var(--primary-600); transition: stroke-dashoffset 0.4s var(--ease); }
.plan-ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.plan-ring-label b { font-size: var(--text-sm); font-weight: var(--fw-bold); color: var(--text-strong); }
.plan-ring-label i { font-style: normal; font-size: 9px; color: var(--text-soft); }

/* included each cycle */
.plan-included-label { font-size: var(--text-2xs, 10px); font-weight: var(--fw-semibold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-soft); margin: 0; }
.plan-items { display: flex; flex-direction: column; }
.plan-item { display: flex; align-items: center; gap: var(--space-3); padding: 7px 0; }
.plan-item + .plan-item { border-top: 1px solid var(--border); }
.plan-item-ico { flex: 0 0 auto; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-md); background: var(--primary-50); color: var(--primary-600); }
.plan-item-ico svg { width: 15px; height: 15px; }
.plan-item-label { flex: 1; min-width: 0; font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-item-qty { flex: 0 0 auto; font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--primary-600); background: var(--primary-50); border-radius: 999px; padding: 2px 8px; }
.plan-items-empty, .plan-tl-empty { color: var(--text-soft); font-size: var(--text-sm); margin: 0; }

/* plan-details button (footer of the card) */
.plan-details-btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; border: none; background: none; padding: 0; color: var(--primary-600); font-size: var(--text-sm); font-weight: var(--fw-semibold); cursor: pointer; }
.plan-details-btn svg { width: 14px; height: 14px; }
@media (hover: hover) { .plan-details-btn:hover { text-decoration: underline; } }

/* empty plan card — when it's the only thing in the rail (no timeline), it
   stretches to the rail's full height with its content centered */
.plan-card--empty { border-style: dashed; align-items: center; text-align: center; padding: var(--space-6) var(--space-5); gap: var(--space-2); }
.cdeliv-rail:has([data-plan-tl][hidden]) [data-plan-card]:has(> .plan-card--empty) { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.cdeliv-rail:has([data-plan-tl][hidden]) .plan-card--empty { flex: 1; justify-content: center; }
.plan-card--empty .plan-empty-ico { width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: var(--primary-50); color: var(--primary-600); margin-bottom: 2px; }
.plan-card--empty .plan-empty-ico svg { width: 18px; height: 18px; }
.plan-card--empty h4 { margin: 0; font-size: var(--text-md); font-weight: var(--fw-bold); color: var(--text-strong); }
.plan-card--empty p { margin: 0 0 var(--space-3); font-size: var(--text-sm); color: var(--text-soft); max-width: 250px; }

/* ---- cycle pager (admin progress card + portal timeline card) ----------- */
.pp-cycle { display: inline-flex; align-items: center; gap: 2px; }
.pp-cycle b { font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-strong); padding: 0 4px; white-space: nowrap; }
.cyc-btn { width: 24px; height: 24px; border: none; background: none; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-soft); cursor: pointer; flex-shrink: 0; }
.cyc-btn svg { width: 14px; height: 14px; }
.cyc-btn:disabled { opacity: 0.3; cursor: default; }
@media (hover: hover) { .cyc-btn:not(:disabled):hover { background: var(--surface-hover); color: var(--text-strong); } }
/* admin progress-card top row: pager pinned left, counts pushed right */
.proj-progress-top:has(.pp-cycle) { justify-content: flex-start; gap: var(--space-3); }
.proj-progress-top .pp-cycle { margin-right: auto; margin-left: -6px; }
/* portal timeline card head */
.pplan-tl-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: 0 0 var(--space-4); }
.pplan-tl-bar h3 { margin: 0; }

/* ---- timeline (shared) --------------------------------------------------- */
.plan-tl-head { display: flex; align-items: center; gap: var(--space-3); margin: 0 0 var(--space-3); }
.plan-tl-head h3 { margin: 0; font-size: var(--text-md); font-weight: var(--fw-bold); color: var(--text-strong); }
.plan-tl-seen { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-xs); font-weight: var(--fw-medium); color: var(--text-soft); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }
.plan-tl-seen svg { width: 12px; height: 12px; }
.plan-tl { display: flex; flex-direction: column; }
.plan-tl-row { display: flex; align-items: flex-start; gap: var(--space-3); position: relative; padding: 0 0 var(--space-4); }
.plan-tl-row:last-child { padding-bottom: 0; }
/* dotted connector between badges (activity-feed style) */
.plan-tl-row::before { content: ""; position: absolute; left: 14px; top: 34px; bottom: 4px; width: 0; border-left: 2px dotted var(--border-strong); }
.plan-tl-row:last-child::before { display: none; }
/* tinted circular icon badge — status carried by the tint */
.plan-tl-badge { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--border); color: var(--text-soft); position: relative; z-index: 1; }
.plan-tl-badge svg { width: 14px; height: 14px; }
.plan-tl-row.is-done .plan-tl-badge { background: var(--success-bg); border-color: transparent; color: var(--success-600); }
.plan-tl-row.is-active .plan-tl-badge { background: var(--primary-50); border-color: transparent; color: var(--primary-600); box-shadow: 0 0 0 3px var(--primary-100); }
.plan-tl-row.is-overdue .plan-tl-badge { background: var(--danger-bg); border-color: transparent; color: var(--danger-600); }
.plan-tl-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-top: 5px; }
/* trailing mini-ring — the deliverable's subtask progress (e.g. 1/3) */
.plan-tl-prog { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; padding-top: 6px; }
.plan-tl-prog svg { display: block; }
.plan-tl-prog .plan-ring-fill { transition: none; }
.plan-tl-prog i { font-style: normal; font-size: var(--text-2xs, 10px); font-weight: var(--fw-semibold); color: var(--text-soft); font-variant-numeric: tabular-nums; }

/* "No date set" bucket — same rows, no connectors (not a sequence) */
.plan-tl-undated { margin-top: var(--space-5); }
.plan-tl-undated .plan-tl-row::before { display: none; }
.plan-tl-undated .plan-tl-row { padding-bottom: var(--space-3); }
.plan-tl-undated .plan-tl-row:last-child { padding-bottom: 0; }
.plan-tl-undated .plan-tl-body { padding-top: 0; justify-content: center; min-height: 30px; }
.plan-tl-title { font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-strong); }
.plan-tl-row.is-done .plan-tl-title { text-decoration: line-through; color: var(--text-soft); }
.plan-tl-sub { font-size: var(--text-xs); color: var(--text-soft); }
.plan-tl-row.is-active .plan-tl-sub { color: var(--primary-600); font-weight: var(--fw-medium); }
.plan-tl-row.is-overdue .plan-tl-sub { color: var(--danger-600); font-weight: var(--fw-medium); }

/* ---- plan sheet + services drawer (shared editor bits) ------------------ */
.plan-sheet-head-title { font-size: var(--text-md); font-weight: var(--fw-bold); color: var(--text-strong); margin-right: var(--space-2); }
.plan-sheet-body { display: flex; flex-direction: column; gap: var(--space-4); }
.plan-field { display: flex; flex-direction: column; gap: 6px; }
.plan-field > label { font-size: var(--text-xs); font-weight: var(--fw-semibold); color: var(--text-soft); }
.plan-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.plan-renews-note { font-size: var(--text-xs); color: var(--text-soft); }

/* item editor rows */
.plan-edit-items { display: flex; flex-direction: column; gap: var(--space-2); }
.plan-edit-item { display: flex; align-items: center; gap: var(--space-2); }
.plan-edit-ico { flex: 0 0 auto; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--primary-600); cursor: pointer; }
.plan-edit-ico svg { width: 15px; height: 15px; }
@media (hover: hover) { .plan-edit-ico:hover { border-color: var(--border-strong); } }
.plan-edit-item .input { flex: 1; min-width: 0; }
.plan-qty { flex: 0 0 auto; display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.plan-qty button { border: none; background: none; width: 26px; height: 32px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-soft); cursor: pointer; font-size: var(--text-md); }
@media (hover: hover) { .plan-qty button:hover { background: var(--surface-hover); color: var(--text-strong); } }
.plan-qty b { min-width: 26px; text-align: center; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-strong); }
.plan-edit-del { flex: 0 0 auto; width: 30px; height: 32px; border: none; background: none; color: var(--text-soft); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; border-radius: var(--radius-md); }
.plan-edit-del svg { width: 14px; height: 14px; }
@media (hover: hover) { .plan-edit-del:hover { color: var(--danger-600); background: var(--danger-bg); } }
.plan-add-item { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; border: none; background: none; padding: 4px 0; color: var(--primary-600); font-size: var(--text-sm); font-weight: var(--fw-semibold); cursor: pointer; }
.plan-add-item svg { width: 14px; height: 14px; }

/* icon picker popover */
.plan-ico-menu { position: fixed; z-index: 1300; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--space-2); display: grid; grid-template-columns: repeat(5, 34px); gap: 4px; }
.plan-ico-menu button { width: 34px; height: 34px; border: none; background: none; border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; color: var(--text-soft); cursor: pointer; }
.plan-ico-menu button.active { background: var(--primary-50); color: var(--primary-600); }
@media (hover: hover) { .plan-ico-menu button:hover { background: var(--surface-hover); color: var(--text-strong); } }
.plan-ico-menu svg { width: 16px; height: 16px; }

/* services drawer split view — opening a service widens the drawer and the
   editor slides in as a panel on the LEFT of the list (the same expand
   pattern as the lead drawer's record-call panel, .drawer.recording). */
/* slimmer resting width than the default drawer — the list is just a name,
   Apply and a kebab; --dw-w also sizes the list column in the split view */
.svc-drawer { --dw-w: clamp(340px, 26vw, 400px); }
.svc-panel { display: none; background: var(--surface); }
@media (min-width: 641px) {
  .drawer.svc-editing { width: min(82%, 960px); }
  /* .svc-collapsing keeps the split LAYOUT alive while the width animates
     back down — the list column stays pinned at its fixed width against the
     right edge and only the panel column squeezes shut. Without it the list
     snaps to flex:1 mid-animation and visibly slides with the drawer edge. */
  .drawer.svc-editing, .drawer.svc-collapsing { flex-direction: row; }
  .drawer.svc-editing .svc-panel, .drawer.svc-collapsing .svc-panel { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; min-height: 0; border-right: 1px solid var(--border); overflow: hidden; }
  .drawer.svc-editing .drawer-main, .drawer.svc-collapsing .drawer-main { flex: 0 0 var(--dw-w); min-width: 0; }
}
.svc-panel-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; opacity: 0; transform: translateX(12px); pointer-events: none; transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease); }
/* the .spacer flex rule lives scoped to .task-detail (tasks.css) — the panel
   sits outside one, so re-apply it here to push the Back control to the edge */
.svc-panel-inner .spacer { flex: 1; }
/* minimal "Collapse ›" (collapses the panel back into the services list) —
   30px tall to match .td-x so both drawer heads line up */
.plan-panel-back { display: inline-flex; align-items: center; gap: 4px; border: none; background: none; height: 30px; padding: 0 8px; flex-shrink: 0; color: var(--text-soft); font-size: var(--text-sm); font-weight: var(--fw-medium); cursor: pointer; border-radius: var(--radius-sm); }
.plan-panel-back svg { width: 15px; height: 15px; }
@media (hover: hover) { .plan-panel-back:hover { color: var(--text-strong); background: var(--surface-hover); } }
.drawer.svc-editing .svc-panel-inner { opacity: 1; transform: none; pointer-events: auto; }

/* services drawer list */
.svc-list { display: flex; flex-direction: column; gap: var(--space-2); }
.svc-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
.svc-row.is-editing { border-color: var(--primary-300); background: var(--primary-50); }
.svc-row-main { flex: 1; min-width: 0; cursor: pointer; }
.svc-row-name { display: block; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-row-meta { display: block; font-size: var(--text-xs); color: var(--text-soft); margin-top: 1px; }
.svc-row .kebab { flex: 0 0 auto; }
.svc-row .btn-sm { flex: 0 0 auto; }
.svc-empty { padding: var(--space-6); text-align: center; color: var(--text-soft); font-size: var(--text-sm); border: 1px dashed var(--border); border-radius: var(--radius-lg); }
.plan-sheet-foot-note { font-size: var(--text-xs); color: var(--text-soft); }

/* ---- client portal: My Plan page ---------------------------------------- */
.pplan { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); min-height: 100%; }
.pplan-hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5) var(--space-6); display: flex; align-items: center; gap: var(--space-5); }
.pplan-hero-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.pplan-hero-main h2 { margin: 0; font-size: var(--text-2xl, 22px); font-weight: var(--fw-bold); color: var(--text-strong); letter-spacing: -0.01em; }
.pplan-hero-main p { margin: 0; font-size: var(--text-sm); color: var(--text-soft); }
.pplan-hero-side { flex: 0 0 200px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.pplan-hero-side .proj-bar { height: 6px; }
.pplan-hero-side span { font-size: var(--text-xs); color: var(--text-soft); text-align: right; }
.pplan-grid { display: grid; grid-template-columns: 5fr 6fr; gap: var(--space-5); align-items: start; }
.pplan-grid--single { grid-template-columns: 1fr; }
.pplan-desc { margin: var(--space-4) 0 0; font-size: var(--text-sm); color: var(--text-soft); line-height: var(--leading-snug, 1.45); white-space: pre-wrap; }
.pplan-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); }
.pplan-card h3 { margin: 0 0 var(--space-4); font-size: var(--text-md); font-weight: var(--fw-bold); color: var(--text-strong); }
.pplan-card .plan-included-label { margin-bottom: var(--space-2); }
/* full-height wrapper around the shared dashed-grid + notepad empty state
   (src/shared/lib/ui.js emptyState) — the illustration floats centered in
   the whole page, matching the Tasks / Content empty views. */
.pplan-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-6); }

@media (max-width: 900px) {
  .pplan { padding: var(--space-4); gap: var(--space-4); }
  .pplan-hero { flex-wrap: wrap; gap: var(--space-4); }
  .pplan-hero-side { flex: 1 1 100%; }
  .pplan-hero-side span { text-align: left; }
  .pplan-grid { grid-template-columns: 1fr; }
}
