/* Deal page (B-024) and its stage bar (B-025). Header and sidebar stay put; only .deal-main scrolls. */
.deal-page { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; background: var(--bg-surface); }

/* ---- Header ---- */
.deal-head { flex: none; padding: var(--sp-6) var(--sp-7) var(--sp-5); border-bottom: 1px solid var(--border); }
.deal-head-top { display: flex; align-items: center; gap: var(--sp-6); min-height: 48px; }
.deal-title-wrap { flex: 1; min-width: 0; margin: 0; font-size: var(--fs-title); line-height: 38px; font-weight: var(--fw-regular); }
/* BUG-139: the title row holds the title and, right after it (8px), the 'Archived' pill. The title only takes
   its own width so the pill sits next to it; while editing, the input takes the whole row. */
.deal-title-row { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-4); }
.deal-title-row > .deal-title-wrap { flex: 0 1 auto; }
.deal-title-row > .deal-title-wrap:has(.deal-title-input) { flex: 1 1 auto; }
.deal-title-row > .darc-pill { flex: none; }
.deal-title {
  max-width: 100%; padding: 0 var(--sp-4); margin-left: calc(-1 * var(--sp-4)); border: 1px solid transparent;
  border-radius: var(--r-md); background: none; color: var(--text); font: inherit; text-align: left; cursor: text;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
  transition: border-color var(--t-fast) var(--ease);
}
.deal-title:hover { border-color: var(--border-strong); }
.deal-title:focus-visible { outline: none; border-color: var(--border-focus); }
.deal-title-input.input {
  width: 100%; height: 40px; margin-left: calc(-1 * var(--sp-4)); padding: 0 var(--sp-4);
  font-size: var(--fs-title); font-weight: var(--fw-regular);
}
.deal-head-right { display: flex; align-items: center; gap: var(--sp-6); flex: none; }
.deal-owner {
  display: flex; align-items: center; gap: var(--sp-4); height: 40px; padding: 0 var(--sp-3) 0 var(--sp-2);
  border: 0; border-radius: var(--r-md); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.deal-owner:hover, .deal-owner[aria-expanded="true"] { background: var(--bg-hover); }
.deal-owner:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.deal-owner:disabled { cursor: default; background: none; opacity: 0.6; }
.deal-owner-av.avatar { width: 32px; height: 32px; }
.deal-owner-text { display: flex; flex-direction: column; line-height: var(--lh-sm); }
.deal-owner-name { font-size: var(--fs-md); font-weight: var(--fw-semibold); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-owner-caption { font-size: var(--fs-sm); color: var(--text-2); }
.deal-head-caret { width: 16px; height: 16px; color: var(--text-2); flex: none; }

/* Header menu buttons (B-029): followers, visibility, '...'; 32px tall like Won / Lost. */
.deal-head-btn.btn { height: var(--control-h); gap: var(--sp-2); padding: 0 var(--sp-4) 0 var(--sp-5); font-weight: var(--fw-semibold); }
.deal-head-btn .ic { width: 16px; height: 16px; }
.deal-vis-btn.btn, .deal-more-btn.btn { padding: 0 var(--sp-4); }
.deal-more-btn.btn { width: var(--control-h); justify-content: center; padding: 0; }
.deal-head-btn:disabled { opacity: 0.6; cursor: default; }

/* Header popovers: owner transfer, followers, visibility. */
.popover.hm-pop { width: 300px; }
.hm-pop-body { padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-4); }
.hm-pop-title { font-size: var(--fs-lg); line-height: var(--lh-lg); font-weight: var(--fw-semibold); }
.hm-pop-label { font-size: var(--fs-md); color: var(--text); }
.hm-pop-actions { display: flex; justify-content: flex-end; gap: var(--sp-4); margin-top: var(--sp-2); }
.hm-pop-actions.is-split { justify-content: space-between; align-items: center; }
.hm-pop-actions.is-split .select-trigger { width: 160px; }
.hm-followers { display: flex; flex-direction: column; max-height: 240px; overflow: auto; }
.hm-follower { display: flex; align-items: center; gap: var(--sp-4); height: 36px; }
.hm-follower-av.avatar { width: 24px; height: 24px; font-size: var(--fs-xs); }
.hm-follower-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hm-empty { color: var(--text-2); padding: var(--sp-3) 0; }

.popover.hm-vis-pop { width: 320px; }
.hm-vis { padding: var(--sp-3) 0; display: flex; flex-direction: column; }
.hm-vis-row {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) 16px; align-items: start; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6); border: 0; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.hm-vis-row:hover, .hm-vis-row:focus-visible { background: var(--menu-hover-bg); color: var(--menu-hover-text); outline: none; }
.hm-vis-ic { width: 20px; height: 20px; color: var(--text-2); }
.hm-vis-text { display: flex; flex-direction: column; }
.hm-vis-title { font-weight: var(--fw-semibold); }
.hm-vis-sub { font-size: var(--fs-sm); line-height: var(--lh-sm); color: var(--text-2); }
.hm-vis-row:hover .hm-vis-ic, .hm-vis-row:hover .hm-vis-sub,
.hm-vis-row:focus-visible .hm-vis-ic, .hm-vis-row:focus-visible .hm-vis-sub { color: inherit; }
.hm-vis-check { width: 16px; height: 16px; color: var(--blue); margin-top: var(--sp-1); }

.popover.hm-more-pop { width: 220px; }
.hm-more { padding: var(--sp-3) 0; }
.hm-merge { display: flex; flex-direction: column; gap: var(--sp-4); }
.hm-merge-text { margin: 0; color: var(--text-2); }

.deal-stage-bar { margin-top: var(--sp-5); }
.deal-breadcrumb { display: flex; align-items: center; gap: var(--sp-3); margin-top: var(--sp-5); font-size: var(--fs-sm); line-height: var(--lh-sm); }
.deal-crumb { color: var(--link); text-decoration: none; }
a.deal-crumb:hover { text-decoration: underline; }
.deal-crumb-sep { width: 12px; height: 12px; color: var(--text-muted); }

/* ---- Body ---- */
.deal-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 400px minmax(0, 1fr); }
.deal-sidebar { min-height: 0; overflow: auto; border-right: 1px solid var(--border); padding: var(--sp-6) var(--sp-6) var(--sp-7); }
.deal-main { min-height: 0; overflow: auto; background: var(--bg-app); padding: var(--sp-7); }

.deal-composer { max-width: 1152px; background: var(--bg-surface); border-radius: var(--r-md); box-shadow: var(--shadow-raised); }
.deal-timeline { max-width: 1152px; margin-top: var(--sp-7); }

/* Loading and not found */
.deal-page.is-loading .deal-head { min-height: 120px; }
.deal-not-found { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-4); padding: var(--sp-9) var(--sp-7); }
.deal-not-found-title { margin: 0; font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
.deal-not-found-text { margin: 0 0 var(--sp-4); color: var(--text-2); }

/* ---- Stage bar (B-025): 24px joined chevrons, 6px arrow on the right, notch on the left ---- */
.stage-bar { display: flex; width: 100%; height: 24px; }
.stage-bar.is-locked .stage-seg { cursor: progress; }
.stage-seg {
  --seg-bg: var(--stage-pick-bg); --seg-text: var(--text-2);
  position: relative; flex: 1 1 0; min-width: 0; height: 24px; margin-left: -4px; padding: 0 var(--sp-5) 0 var(--sp-6);
  border: 0; background: var(--seg-bg); color: var(--seg-text); font: inherit; font-size: var(--fs-sm); line-height: 24px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 50%, calc(100% - 6px) 100%, 0 100%, 6px 50%);
  transition: background var(--t-fast) var(--ease);
}
.stage-seg:first-child { margin-left: 0; padding-left: var(--sp-5); border-radius: var(--r-sm) 0 0 var(--r-sm);
  clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 50%, calc(100% - 6px) 100%, 0 100%); }
.stage-seg:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 6px 50%); }
.stage-seg:only-child { clip-path: none; border-radius: var(--r-sm); }
.stage-seg-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-seg:hover { --seg-bg: var(--stage-pick-hover); }
.stage-seg.passed, .stage-seg.current { --seg-bg: var(--green); --seg-text: var(--text-inverse); }
.stage-seg.passed:hover, .stage-seg.current:hover { --seg-bg: var(--green-hover); }
.stage-seg.current.won { --seg-bg: var(--won-bg); --seg-text: var(--green); }
.stage-seg.current.won:hover { --seg-bg: var(--won-bg-hover); }
.stage-seg.current.lost { --seg-bg: var(--lost-bg); --seg-text: var(--red); }
.stage-seg.current.lost:hover { --seg-bg: var(--lost-bg-hover); }
.stage-seg:focus-visible { outline: none; --seg-bg: var(--blue-bright); --seg-text: var(--text-inverse); }
.stage-seg-spinner { width: 12px; height: 12px; }
.stage-seg.passed .stage-seg-spinner, .stage-seg.current .stage-seg-spinner {
  border-color: rgba(255, 255, 255, 0.35); border-top-color: var(--text-inverse);
}
.stage-bar[aria-busy="true"] .stage-seg { cursor: progress; }
.stage-seg[aria-disabled="true"] { cursor: default; }

@media (max-width: 900px) {
  .deal-body { grid-template-columns: 300px minmax(0, 1fr); }
  .deal-head-top { flex-wrap: wrap; }
}
/* LAUNCH-TEST r1 #6: on a phone the owner and the Won / Lost / Reopen / Open matter in Clio buttons ran ~815px wide
   off the screen. Under 640px they wrap onto their own lines below the title, and the stage bar scrolls sideways
   with readable stage names instead of 'O… C… Q…'. */
@media (max-width: 640px) {
  .deal-head { padding: var(--sp-5) var(--sp-4) var(--sp-4); }
  .deal-head-top { gap: var(--sp-4); }
  .deal-head-right { flex: 1 1 100%; min-width: 0; flex-wrap: wrap; gap: var(--sp-3); }
  .stage-bar { overflow-x: auto; scrollbar-width: none; }
  .stage-bar::-webkit-scrollbar { display: none; }
  .stage-seg { flex: 0 0 auto; min-width: 88px; }
}

/* "Deal won" celebration (B-096, components/won-celebration.js) */
.won { position: relative; }
.won-confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 10000; }
.won-hero { text-align: center; padding: var(--sp-3) 0 var(--sp-5); }
.won-emoji { font-size: 40px; line-height: 1; }
.won-title { margin: var(--sp-3) 0 var(--sp-2); font-size: 24px; font-weight: var(--fw-bold, 700); color: var(--green); }
.won-deal { color: var(--text-2); }
.won-deal strong { color: var(--text); }
.won-next { border-top: 1px solid var(--border); padding-top: var(--sp-5); }
.won-next-title { font-weight: var(--fw-semibold); margin-bottom: var(--sp-2); }
.won-next-text { margin: 0 0 var(--sp-4); color: var(--text-2); font-size: var(--fs-sm); }
.won-checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.won-check { display: grid; grid-template-columns: 20px 150px 1fr; align-items: baseline; gap: var(--sp-3); font-size: var(--fs-md); }
.won-check-mark { font-weight: 700; text-align: center; }
.won-check.is-ok .won-check-mark { color: var(--green); }
.won-check.is-missing .won-check-mark, .won-check.is-missing .won-check-value { color: #b7791f; }
.won-check-label { color: var(--text-2); }
.won-check-value { overflow-wrap: anywhere; }
@media (max-width: 480px) { .won-check { grid-template-columns: 20px 1fr; } .won-check-value { grid-column: 2; } }
