/* Ô tổng — một khối cho khung WL26 và vỏ Cổng đối tác (Chuẩn chung "Ô tổng").
 *
 * Mẩu: core/templates/core/stats/_tiles.html; Python: core/stat_tiles.py (StatStrip,
 * StatCell); JS: core/static/core/js/stat-tiles.js (WL26.stats.set).
 *
 * Màu CHỈ từ biến `--wl-stat-*`. Khung WL26 lấy biến của Unfold ở dưới; Cổng đối tác không
 * nạp CSS của Unfold, nên vỏ cổng gán lại mọi biến này bằng biến của chính nó
 * (partners/_shared_tools.html), sáng / tối theo vỏ.
 *
 * Hai dáng dải: dải thường (3–4 ô) và dải trong thanh dính đáy của màn nhiều bước
 * (`.wl-stats--dock`, 1–5 ô). Dáng theo bề ngang của chính dải (container query), không theo
 * màn hình: cùng một dải đứng trong cột hẹp hay trong thanh dính đáy đều đúng.
 */

:root {
  --wl-stat-accent: var(--color-primary-600);
  --wl-stat-on-accent: var(--color-white);
  --wl-stat-bg: var(--color-white);
  --wl-stat-line: var(--color-base-200);
  --wl-stat-label: var(--color-base-500);
  --wl-stat-ink: var(--color-font-important-light);
  --wl-stat-zero: var(--color-base-400);
  --wl-stat-waiting: var(--color-orange-700);
  --wl-stat-in-progress: var(--color-blue-700);
  --wl-stat-done: var(--color-green-700);
  --wl-stat-rejected: var(--color-red-700);
}

.dark {
  --wl-stat-bg: var(--color-base-900);
  --wl-stat-line: var(--color-base-800);
  --wl-stat-label: var(--color-base-400);
  --wl-stat-ink: var(--color-font-important-dark);
  --wl-stat-zero: var(--color-base-500);
  --wl-stat-waiting: var(--color-orange-400);
  --wl-stat-in-progress: var(--color-blue-400);
  --wl-stat-done: var(--color-green-400);
  --wl-stat-rejected: var(--color-red-400);
}

/* ---------- khung dải ---------- */

.wl-stats {
  container-type: inline-size;
  overflow: hidden;
  border: 1px solid var(--wl-stat-line);
  border-radius: 8px;
  background: var(--wl-stat-bg);
}

/* Vạch giữa các ô là khe 1px của lưới, lộ nền màu vạch. */
.wl-stats__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--wl-stat-line);
}

/* ---------- một ô ---------- */

.wl-stat {
  display: block;
  min-width: 0;
  padding: 10px 14px;
  background: var(--wl-stat-bg);
  color: var(--wl-stat-ink);
  text-decoration: none;
}

a.wl-stat:hover {
  background: color-mix(in srgb, var(--wl-stat-accent) 6%, var(--wl-stat-bg));
}

a.wl-stat:focus-visible {
  outline: 2px solid var(--wl-stat-accent);
  outline-offset: -2px;
}

.wl-stat__label {
  display: block;
  overflow-wrap: anywhere;
  color: var(--wl-stat-label);
  font-size: 12px;
  line-height: 1.3;
}

.wl-stat__value {
  display: block;
  margin-top: 2px;
  white-space: nowrap;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.wl-stat__num {
  font-variant-numeric: tabular-nums;
}

.wl-stat__unit {
  color: var(--wl-stat-label);
  font-size: 13px;
  font-weight: 400;
}

.wl-stat__sub {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--wl-stat-label);
  font-size: 12px;
}

/* Màu số theo nhóm Trạng thái quy trình; số 0 xám (đứng sau nên thắng màu nhóm). */
.wl-stat[data-tone="waiting"] .wl-stat__value { color: var(--wl-stat-waiting); }
.wl-stat[data-tone="in_progress"] .wl-stat__value { color: var(--wl-stat-in-progress); }
.wl-stat[data-tone="done"] .wl-stat__value { color: var(--wl-stat-done); }
.wl-stat[data-tone="rejected"] .wl-stat__value { color: var(--wl-stat-rejected); }
.wl-stat[data-tone="inactive"] .wl-stat__value,
.wl-stat[data-zero] .wl-stat__value { color: var(--wl-stat-zero); }

/* Ô chính: nền màu chính, chữ trên màu chính; không bao giờ xám. */
.wl-stat.wl-stat--primary,
.wl-stat.wl-stat--primary .wl-stat__label,
.wl-stat.wl-stat--primary .wl-stat__value,
.wl-stat.wl-stat--primary .wl-stat__unit,
.wl-stat.wl-stat--primary .wl-stat__sub {
  color: var(--wl-stat-on-accent);
}

.wl-stat.wl-stat--primary {
  background: var(--wl-stat-accent);
}

/* ---------- dải thường: hẹp hai cột, rộng một hàng ---------- */

/* Hẹp: ô chính một hàng riêng; ô cuối đứng một mình thì trải hết hàng. */
@container (max-width: 639.98px) {
  .wl-stats--lead .wl-stat--primary,
  .wl-stats:not(.wl-stats--lead) .wl-stats__grid > .wl-stat:last-child:nth-child(odd),
  .wl-stats--lead .wl-stats__grid > .wl-stat:last-child:nth-child(even) {
    grid-column: 1 / -1;
  }
}

@container (min-width: 640px) {
  .wl-stats[data-count="3"] .wl-stats__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .wl-stats[data-count="4"] .wl-stats__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- dải trong thanh dính đáy ---------- */

/* Hẹp: ô chính một hàng (nhãn trái, số phải, cùng dòng); các ô khác ba ô một hàng, chia đều
 * chỗ còn lại của hàng. Không bóng thẻ: thanh dính đáy đã là một khối. */
.wl-stats--dock .wl-stats__grid {
  display: flex;
  flex-wrap: wrap;
}

.wl-stats--dock .wl-stat {
  flex: 1 1 30%;
  padding: 6px 12px;
}

.wl-stats--dock .wl-stat__label {
  font-size: 12px;
}

.wl-stats--dock .wl-stat__value {
  margin-top: 0;
  font-size: 15px;
}

.wl-stats--dock .wl-stat--primary {
  display: flex;
  flex-basis: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.wl-stats--dock .wl-stat--primary .wl-stat__label {
  font-size: 13px;
  font-weight: 600;
}

.wl-stats--dock .wl-stat--primary .wl-stat__value {
  margin-top: 0;
  font-size: 18px;
}

.wl-stats--dock .wl-stat--primary .wl-stat__sub {
  display: none;
}

/* Rộng: một hàng, ô chính rộng hơn một chút, nhãn trên số như dải thường. */
@container (min-width: 640px) {
  .wl-stats--dock .wl-stats__grid {
    flex-wrap: nowrap;
  }

  .wl-stats--dock .wl-stat {
    flex: 1 1 0;
  }

  .wl-stats--dock .wl-stat--primary {
    display: block;
    flex: 1.4 1 0;
  }

  .wl-stats--dock .wl-stat--primary .wl-stat__value {
    margin-top: 2px;
  }

  .wl-stats--dock .wl-stat__value {
    font-size: 16px;
  }

  .wl-stats--dock .wl-stat--primary .wl-stat__value {
    font-size: 18px;
  }
}
