/* Màn "Đơn hàng": mọi class có tiền tố od- để không đụng màn khác. */

/* Ba số công nợ đầu màn */
.od-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
/* Quá hẹn: viền 1px quanh cả thẻ đổi màu, nền đỏ nhạt hiện dần phía dưới chữ (kèm chữ "đợt quá hẹn", không chỉ màu) */
.od-stat {
  position: relative;
  isolation: isolate;
  display: grid;
  gap: 2px;
  overflow: hidden;
}
.od-stat::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  background: var(--danger-soft);
  opacity: 0;
  transition: opacity var(--duration-slide) var(--ease-out);
}
.od-stat.is-alert {
  border-color: var(--danger);
}
.od-stat.is-alert::before {
  opacity: 1;
}
.od-stat-icon {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}
.od-stat-overdue .od-stat-icon {
  background: var(--warn-soft);
  color: var(--warn);
}
.od-stat.is-alert .od-stat-icon {
  background: var(--danger-soft);
  color: var(--danger);
}
.od-stat-collected .od-stat-icon {
  background: var(--ok-soft);
  color: var(--ok);
}
.od-stat-label {
  color: var(--muted);
  font-weight: 500;
}
.od-stat-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.od-stat-sub {
  font-size: 13px;
}

/* Thanh công cụ: lọc có chỉ báo trượt, ô tìm */
.od-count {
  margin-left: 4px;
  color: var(--muted);
  font-size: 12px;
}
.seg-btn[aria-selected='true'] .od-count {
  color: var(--accent);
}
.od-search {
  position: relative;
  display: flex;
  align-items: center;
  margin-left: auto;
  width: min(300px, 100%);
}
.od-search .i {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}
.od-search-input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition:
    border-color var(--duration-base),
    box-shadow var(--duration-base);
}
.od-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Danh sách đơn: hàng có cột ở màn rộng, thẻ ở điện thoại */
.od-table {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.od-head,
.od-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(
      0,
      1.4fr
    );
  align-items: center;
  gap: 14px;
}
.od-head {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.od-item + .od-item {
  border-top: 1px solid var(--line);
}
.od-row {
  position: relative;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  background: none;
  text-align: left;
  transition:
    background var(--duration-base),
    transform var(--duration-fast) var(--ease-out);
}
.od-row:active {
  transform: scale(0.995);
}
.od-row:focus-visible {
  outline-offset: -2px;
}
@media (hover: hover) {
  .od-row:hover {
    background: var(--surface-2);
  }
  .od-row.is-overdue:hover::before {
    opacity: 0.7;
  }
}
/* Đơn có đợt quá hẹn: viền 1px quanh cả hàng và nền đỏ nhạt hiện dần, đi kèm huy hiệu chữ "Quá hẹn" */
.od-row.is-overdue {
  isolation: isolate;
}
.od-row.is-overdue::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  transition: opacity var(--duration-base);
  animation: fade-in var(--duration-enter) var(--ease-out) var(--duration-base) backwards;
}
.od-main,
.od-customer {
  display: grid;
  min-width: 0;
}
.od-code {
  color: var(--accent);
}
.od-customer {
  overflow-wrap: anywhere;
}
.od-customer small {
  font-size: 12px;
}
.od-owner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.od-owner span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.od-total {
  font-weight: 600;
}
.od-progress {
  display: flex;
  align-items: center;
  gap: 8px;
}
.od-bar {
  position: relative;
  display: block;
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.od-bar-fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--ok);
  transform: scaleX(var(--p, 0));
  transform-origin: left;
  transition: transform var(--duration-enter) var(--ease-out);
}
.stagger .od-bar-fill {
  transition-delay: calc(var(--i, 0) * var(--stagger-step) + var(--duration-base));
}
.od-pct {
  min-width: 38px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}
.od-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.od-late .i {
  width: 14px;
  height: 14px;
}
.od-new {
  animation: od-slide-in var(--duration-slide) var(--ease-out);
}
@keyframes od-slide-in {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
}
.od-fade {
  animation: fade-in var(--duration-slide) var(--ease-out);
}

/* Ngăn kéo chi tiết */
.od-panel {
  display: grid;
  gap: 20px;
}
.od-sec {
  display: grid;
  gap: 10px;
}
.od-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.od-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 0;
}
.od-fact dt {
  color: var(--muted);
  font-size: 12px;
}
.od-fact dd {
  margin: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.od-link {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: transform var(--duration-fast) var(--ease-out);
}
.od-link:active {
  transform: scale(0.97);
}
.od-paid {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.od-paid-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
}
.od-paid .od-bar {
  flex: none;
  height: 10px;
  background: var(--surface);
}
.od-owing {
  color: var(--warn);
  font-weight: 600;
}
.od-owing.is-clear {
  color: var(--ok);
}

/* Dòng thời gian các đợt thu: đường nối mọc dần, chấm bật ra, dấu tích vẽ dần theo thứ tự */
.od-timeline {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: 0 0 0 36px;
  list-style: none;
}
.od-step {
  position: relative;
}
.od-step::before {
  content: '';
  position: absolute;
  top: 28px;
  bottom: -18px;
  left: -25px;
  width: 2px;
  background: var(--line);
  transform-origin: top;
}
.od-step:last-child::before {
  display: none;
}
.od-step.is-paid::before {
  background: var(--ok);
}
.od-dot {
  position: absolute;
  top: 2px;
  left: -36px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  transition:
    background var(--duration-base),
    border-color var(--duration-base);
}
.od-step.is-overdue .od-dot {
  border-color: var(--danger);
}
.od-step.is-paid .od-dot {
  border-color: var(--ok);
  background: var(--ok);
  color: var(--surface);
}
.od-check {
  width: 14px;
  height: 14px;
  stroke-width: 3;
}
.od-check path {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}
.od-check.is-draw path {
  animation: od-draw var(--duration-enter) var(--ease-out) backwards;
}
.od-timeline.is-drawing .od-step::before {
  animation: od-line var(--duration-enter) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * var(--duration-slide) + var(--duration-base));
}
.od-timeline.is-drawing .od-dot {
  animation: pop var(--duration-slide) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * var(--duration-slide));
}
.od-timeline.is-drawing .od-check path {
  animation: od-draw var(--duration-slide) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * var(--duration-slide) + var(--duration-base));
}
.od-timeline.is-drawing .od-step-body {
  animation: rise var(--duration-slide) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * var(--duration-slide));
}
@keyframes od-line {
  from {
    transform: scaleY(0);
  }
}
@keyframes od-draw {
  from {
    stroke-dashoffset: 1;
  }
}
.od-step-body {
  display: grid;
  justify-items: start;
  gap: 4px;
}
.od-step-title {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.od-step-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.od-step-meta.is-late {
  color: var(--danger);
  font-weight: 500;
}
.od-step-meta .i {
  width: 16px;
  height: 16px;
}

/* Sửa đợt thu */
.od-editor {
  display: grid;
  gap: 12px;
}
.od-locked {
  display: grid;
  gap: 6px;
}
.od-locked li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}
.od-locked .i {
  width: 16px;
  height: 16px;
  color: var(--ok);
}
.od-locked .num {
  margin-left: auto;
  color: var(--text);
}
.od-split {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.od-edit-rows {
  display: grid;
  gap: 8px;
}
.od-edit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 32px;
  align-items: end;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.od-in {
  animation: rise var(--duration-slide) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * var(--stagger-step));
}
.od-cell {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.od-cap {
  color: var(--muted);
  font-size: 12px;
}
.od-input {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition:
    border-color var(--duration-base),
    box-shadow var(--duration-base);
}
.od-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.od-input[aria-invalid='true'] {
  border-color: var(--danger);
}
.od-add {
  justify-self: start;
}
.od-edit-sum {
  color: var(--muted);
  font-size: 13px;
}
.od-edit-sum.is-off {
  color: var(--warn);
  font-weight: 500;
}
.od-block-error {
  min-height: 0;
}
.od-block-error.has-error {
  color: var(--danger);
  animation: fade-in var(--duration-base) var(--ease-out);
}
.od-block-error.shake {
  animation: shake var(--duration-slide) var(--ease-in-out);
}
.od-edit-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* Sản phẩm và tổng tiền */
.od-lines {
  display: grid;
  gap: 8px;
}
.od-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.od-line-name {
  display: grid;
  min-width: 0;
  overflow-wrap: anywhere;
}
.od-line-name small {
  font-size: 12px;
}
.od-totals {
  display: grid;
  gap: 6px;
  margin: 4px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.od-total-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.od-total-row dd {
  margin: 0;
}
.od-total-row.is-grand {
  font-size: 16px;
  font-weight: 700;
}
.od-total-row.is-grand dd {
  color: var(--accent);
}

@media (max-width: 1100px) {
  .od-head,
  .od-row {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1.4fr);
  }
  .od-head span:nth-child(2),
  .od-owner {
    display: none;
  }
}
@media (max-width: 900px) {
  .od-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .od-stat-outstanding {
    grid-column: 1 / -1;
  }
}

/* Điện thoại: số công nợ một cột, bộ lọc giãn đủ rộng, mỗi đơn là một thẻ */
@media (max-width: 720px) {
  .od-stats {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .od-stat {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: 12px;
    padding: 12px 14px;
  }
  .od-stat-icon {
    grid-row: span 3;
    margin: 0;
  }
  .od-stat-value {
    font-size: 19px;
  }
  .od-tools,
  .od-filter,
  .od-filter .seg {
    width: 100%;
  }
  .od-filter .seg-btn {
    flex: 1;
    padding: 0 6px;
  }
  .od-search {
    margin-left: 0;
    width: 100%;
  }
  .od-head {
    display: none;
  }
  .od-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'main total'
      'progress progress'
      'badges badges';
    gap: 8px 12px;
    padding: 14px;
  }
  .od-main {
    grid-area: main;
  }
  .od-total {
    grid-area: total;
    align-self: start;
  }
  .od-progress {
    grid-area: progress;
  }
  .od-badges {
    grid-area: badges;
  }
  .od-facts {
    grid-template-columns: 1fr;
  }
  .od-edit-row {
    grid-template-columns: minmax(0, 1fr) 32px;
  }
  .od-edit-row .od-cell:nth-child(2) {
    grid-row: 2;
  }
  .od-del {
    grid-row: 1;
    grid-column: 2;
  }
}

@media (pointer: coarse) {
  .od-link,
  .od-row {
    min-height: 44px;
  }
  .od-del {
    width: 44px;
    height: 44px;
  }
  .od-edit-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px;
  }
}
@media (pointer: coarse) and (max-width: 720px) {
  .od-edit-row {
    grid-template-columns: minmax(0, 1fr) 44px;
  }
}
