/* Màn Pipeline: kanban, danh sách, thẻ cơ hội, kéo thả. Tiền tố pl-. Màu cột lấy từ dữ liệu qua --stage-color. */

.pl-summary {
  font-variant-numeric: tabular-nums;
}
.pl-toolbar {
  align-items: center;
}
.pl-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pl-select,
.pl-stage-select {
  height: 40px;
  max-width: 100%;
  padding: 0 28px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition:
    border-color var(--duration-base),
    box-shadow var(--duration-base);
}
.pl-select:focus,
.pl-stage-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.pl-filter {
  display: block;
  min-width: 0;
}
.pl-clear {
  animation: pop var(--duration-slide) var(--ease-out);
}
.pl-clear[hidden] {
  display: none;
}
.pl-modal-note {
  margin-bottom: 14px;
}
.pl-delete {
  margin-right: auto;
}

/* ---------- Bảng kanban ---------- */
.pl-board {
  display: flex;
  align-items: stretch;
  gap: 12px;
  max-height: calc(100vh - 250px);
  min-height: 360px;
  padding: 2px 2px 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  outline: none;
}
.pl-col {
  display: flex;
  flex: 0 0 288px;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  scroll-snap-align: start;
  transition:
    transform var(--duration-base) var(--ease-out),
    border-color var(--duration-base),
    box-shadow var(--duration-base),
    background var(--duration-base);
}
.pl-col .pl-card.stagger {
  animation-delay: calc((var(--i, 0) + var(--col-i, 0) + 1) * var(--stagger-step));
}
.pl-col.is-target {
  transform: translateY(-3px);
  border-color: var(--stage-color);
  background: color-mix(in srgb, var(--stage-color) 10%, var(--surface-2));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--stage-color) 28%, transparent);
}
.pl-col-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 12px 8px;
  border-bottom: 2px solid var(--stage-color);
  border-radius: var(--radius) var(--radius) 0 0;
}
.pl-col-head .i {
  width: 16px;
  height: 16px;
  color: var(--stage-color);
}
.pl-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--stage-color);
}
.pl-col-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pl-count {
  background: var(--surface);
}
.pl-total {
  flex-basis: 100%;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.pl-col-body {
  display: grid;
  flex: 1;
  align-content: start;
  gap: 8px;
  padding: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.pl-drop-hint {
  display: grid;
  place-items: center;
  min-height: 84px;
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  transition:
    border-color var(--duration-base),
    color var(--duration-base);
}
.pl-col.is-target .pl-drop-hint {
  border-color: var(--stage-color);
  color: var(--text);
}
.pl-kind-lost .pl-card {
  opacity: 0.82;
}

/* ---------- Thẻ cơ hội ---------- */
.pl-card {
  position: relative;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  user-select: none;
  transition:
    transform var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base),
    border-color var(--duration-base),
    opacity var(--duration-base);
}
.pl-card:active {
  transform: scale(0.985);
}
.pl-card.is-origin {
  opacity: 0.35;
  border-style: dashed;
}
.pl-card.is-ghosted {
  opacity: 0;
}
.pl-card.is-lifted {
  transform: translateY(-5px) rotate(1.2deg);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}
.pl-ghost {
  position: fixed;
  z-index: 150;
  margin: 0;
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  cursor: grabbing;
  pointer-events: none;
  animation: none;
  transition: none;
  will-change: transform;
  transform-origin: 50% 50%;
}
body.pl-dragging {
  cursor: grabbing;
  user-select: none;
}
.pl-card-top {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}
.pl-card-title {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.pl-grip {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  margin: -4px -6px -4px 0;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}
.pl-edit {
  margin: -4px 0 -4px auto;
  opacity: 0;
  transition:
    opacity var(--duration-base),
    transform var(--duration-fast) var(--ease-out),
    border-color var(--duration-base);
}
.pl-card:focus-within .pl-edit {
  opacity: 1;
}
@media (hover: none) {
  .pl-edit {
    opacity: 1;
  }
}
.pl-card-who {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pl-card-mid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.pl-card-value {
  font-size: 16px;
}
.pl-due {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}
.pl-due .i,
.pl-stale .i {
  width: 14px;
  height: 14px;
}
.pl-due.is-overdue {
  color: var(--danger);
  font-weight: 600;
}
.pl-card-reason {
  color: var(--muted);
  font-size: 12px;
}
.pl-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.pl-owner {
  line-height: 0;
}
.pl-score {
  min-height: 24px;
  border: 0;
  transition:
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-base);
}
.pl-score:active {
  transform: scale(0.94);
}
@media (hover: hover) {
  .pl-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
  }
  .pl-card:hover .pl-edit {
    opacity: 1;
  }
  .pl-card:hover:active {
    transform: scale(0.985);
  }
  .pl-score:hover {
    box-shadow: 0 0 0 2px var(--line);
  }
}

/* ---------- Popover điểm khách ---------- */
.pl-pop {
  position: fixed;
  z-index: 160;
  display: grid;
  gap: 8px;
  width: min(280px, calc(100vw - 16px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--duration-base) var(--ease-out);
  pointer-events: none;
}
.pl-pop[hidden] {
  display: none;
}
.pl-pop.is-leaving {
  opacity: 0;
  transform: scale(0.96);
  transition:
    opacity var(--duration-fast),
    transform var(--duration-fast);
}
.pl-pop-title {
  font-weight: 600;
}
.pl-pop-list {
  display: grid;
  gap: 4px;
}
.pl-pop-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.pl-pop-note {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Danh sách ---------- */
.pl-list {
  animation: fade-in var(--duration-slide) var(--ease-out);
}
.pl-row.stagger {
  animation-delay: calc(var(--i, 0) * 25ms);
}
.pl-tbl td {
  vertical-align: middle;
}
.pl-tbl td[data-label='Cột'] .pl-dot {
  display: inline-block;
  margin-right: 8px;
  vertical-align: middle;
}
.pl-stage-select {
  height: 34px;
}
.pl-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-weight: 600;
  text-align: left;
  transition: color var(--duration-base);
}
@media (hover: hover) {
  .pl-link:hover {
    color: var(--accent);
  }
}
.pl-owner-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.pl-stale {
  margin-left: 6px;
}

/* ---------- Nhóm dự báo trên thẻ ---------- */
.pl-fc {
  position: relative;
  overflow: hidden;
}
/* Nhóm cũ chồng lên nhóm mới rồi mờ dần: đổi màu bằng mờ chéo, chỉ dùng opacity. */
.pl-fc-old {
  position: absolute;
  inset: 0;
  justify-content: center;
  animation: pl-fade-out var(--duration-slide) var(--ease-out) forwards;
}
@keyframes pl-fade-out {
  to {
    opacity: 0;
  }
}

/* ---------- Ô đối thủ trượt mở ---------- */
.pl-reveal {
  animation: pl-reveal-in var(--duration-slide) var(--ease-out);
}
.pl-reveal[hidden] {
  display: none;
}
.pl-reveal.is-closing {
  animation: pl-reveal-out var(--duration-slide) var(--ease-in-out) forwards;
}
@keyframes pl-reveal-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
    clip-path: inset(0 0 100% 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}
@keyframes pl-reveal-out {
  from {
    clip-path: inset(0 0 0 0);
  }
  to {
    opacity: 0;
    transform: translateY(-6px);
    clip-path: inset(0 0 100% 0);
  }
}

/* ---------- Hộp sửa cơ hội: nhóm dự báo, sản phẩm ---------- */
.pl-block-title {
  font-size: 14px;
  font-weight: 600;
}
.pl-block-note {
  font-size: 12px;
}
.pl-fc-pick {
  display: grid;
  gap: 6px;
  margin: 4px 0 12px;
}
.pl-seg-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
.pl-seg-scroll .seg-btn {
  flex: none;
  white-space: nowrap;
}
.field.is-locked input {
  background: var(--surface-2);
  cursor: default;
}
.pl-value-note {
  margin-top: -2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  animation: fade-in var(--duration-base) var(--ease-out);
}
.pl-value-note[hidden] {
  display: none;
}
.pl-items {
  display: grid;
  gap: 8px;
}
.pl-items.shake {
  animation: shake 360ms var(--ease-in-out);
}
.pl-items-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pl-picker-row {
  display: flex;
  flex: 1 1 320px;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.pl-picker {
  flex: 1 1 200px;
  min-width: 0;
}
.pl-lines {
  display: grid;
  gap: 8px;
}
.pl-line {
  display: grid;
  grid-template-areas: 'name qty disc sum del';
  grid-template-columns: minmax(0, 1fr) 76px 84px 128px 36px;
  align-items: end;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--duration-base);
}
.pl-line.is-entering {
  animation: pl-line-in var(--duration-slide) var(--ease-out);
}
.pl-line.is-leaving {
  pointer-events: none;
  transform-origin: top center;
  animation: pl-line-out var(--duration-base) var(--ease-in-out) forwards;
}
.pl-line.is-invalid {
  border-color: var(--danger);
}
@keyframes pl-line-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
}
@keyframes pl-line-out {
  to {
    opacity: 0;
    transform: translateX(-16px) scaleY(0.6);
  }
}
.pl-line-name {
  display: grid;
  grid-area: name;
  gap: 2px;
  min-width: 0;
  font-size: 13px;
}
.pl-line-name strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}
.pl-line-qty {
  grid-area: qty;
}
.pl-line-disc {
  grid-area: disc;
}
.pl-line-sum {
  grid-area: sum;
  text-align: right;
}
.pl-line-del {
  grid-area: del;
}
.pl-line-cell {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.pl-cap {
  color: var(--muted);
  font-size: 12px;
}
.pl-line-total {
  font-weight: 600;
}
.pl-num-input {
  width: 100%;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition:
    border-color var(--duration-base),
    box-shadow var(--duration-base);
}
.pl-num-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.pl-line.is-invalid .pl-num-input:invalid {
  border-color: var(--danger);
}
.pl-lines-empty {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
  animation: fade-in var(--duration-base) var(--ease-out);
}
.pl-lines-empty[hidden] {
  display: none;
}
.pl-lines-error {
  min-height: 0;
}
.pl-lines-error.has-error {
  color: var(--danger);
  animation: fade-in var(--duration-base) var(--ease-out);
}
@media (pointer: coarse) {
  .pl-select,
  .pl-num-input {
    min-height: 44px;
  }
}

/* ---------- Di động ---------- */
@media (max-width: 720px) {
  .pl-toolbar {
    align-items: stretch;
  }
  .pl-toolbar .seg {
    width: 100%;
  }
  .pl-toolbar .seg-btn {
    flex: 1;
  }
  .pl-filters {
    display: grid;
    flex: 1 1 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .pl-select {
    width: 100%;
    padding: 0 20px 0 8px;
    font-size: 13px;
    text-overflow: ellipsis;
  }
  .pl-board {
    align-items: flex-start;
    max-height: none;
    min-height: 0;
    scroll-snap-type: x mandatory;
    margin: 0 -12px;
    padding: 2px 12px 12px;
    scroll-padding: 0 12px;
  }
  .pl-col {
    flex-basis: 85%;
  }
  .pl-col-body {
    max-height: 60vh;
  }
  .pl-edit {
    opacity: 1;
  }
  .pl-tbl thead {
    display: none;
  }
  .pl-tbl,
  .pl-tbl tbody,
  .pl-tbl tr,
  .pl-tbl td {
    display: block;
  }
  .pl-tbl tr {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
  }
  .pl-tbl td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    border: 0;
    white-space: normal;
    text-align: right;
  }
  .pl-tbl td::before {
    content: attr(data-label);
    flex: none;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  .pl-tbl td[data-label='Cột'] {
    display: flex;
  }
  .pl-line {
    grid-template-areas:
      'name name name del'
      'qty disc sum sum';
    grid-template-columns: repeat(3, minmax(0, 1fr)) 44px;
    align-items: start;
  }
  .pl-line-sum {
    text-align: left;
  }
  .pl-line-del {
    justify-self: end;
  }
  .pl-picker-row {
    flex-basis: 100%;
  }
  .pl-picker-row .btn {
    flex: 1 1 auto;
  }
}
