@import "tokens/fonts.css";
@import "tokens/colors.css";
@import "tokens/typography.css";
@import "tokens/spacing.css";
@import "tokens/base.css";
@import "tokens/components.css";

/* ── Ghi đè cục bộ (KHÔNG sửa tokens/, chúng sync từ design system) ─────────── */

/* Ô KPI: số 40px vs nhãn 12px = chênh 3,3 lần, số át hết nhãn. Kéo lại gần nhau.
   Chỉ scope trong .stat-tile để không đụng các số hero khác. */
.stat-tile .text-hero-num { font-size: 30px; letter-spacing: -0.015em; }
.stat-tile .stat-tile__label .text-overline {
  font-size: var(--text-sm);        /* 13px, thay vì 12px */
  letter-spacing: 0.04em;           /* overline gốc giãn 0.08em → khó đọc ở nhãn dài */
  line-height: 1.35;
  color: var(--text-2);             /* text-3 quá nhạt cạnh số đậm */
}
.stat-tile .text-hero-num > span { font-size: var(--text-md) !important; }  /* đơn vị */

/* Hàng KPI cuộn ngang khi > 3 ô. Ẩn thanh cuộn, điều hướng bằng nút. */
.fmi-kpi-row { display: flex; gap: 16px; overflow-x: auto; scroll-behavior: smooth;
  scroll-snap-type: x proximity; scrollbar-width: none; -ms-overflow-style: none; }
.fmi-kpi-row::-webkit-scrollbar { display: none; }
.fmi-kpi-row > * { flex: 0 0 calc((100% - 32px) / 3); min-width: 230px; scroll-snap-align: start; }

/* Hàng card (AI Agents): tối đa 3 card/khung, dư thì cuộn ngang — cùng phong cách rail KPI.
   min-width rộng hơn KPI vì card agent có mô tả + 2 nút. */
.fmi-card-rail { display: flex; gap: 16px; overflow-x: auto; scroll-behavior: smooth;
  scroll-snap-type: x proximity; scrollbar-width: none; -ms-overflow-style: none; }
.fmi-card-rail::-webkit-scrollbar { display: none; }
.fmi-card-rail > * { flex: 0 0 calc((100% - 32px) / 3); min-width: 300px; scroll-snap-align: start; }

/* Nhãn 3 dòng + footnote 4 dòng làm các ô KPI cao lệch nhau. Kẹp lại. */
.stat-tile .stat-tile__label .text-overline {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.stat-tile .text-caption {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── Panel tiến trình run (RunPanel tự dựng trong screens.jsx) ─────────────────────────
   Cố ý KHÔNG dùng RunProgress của design system: nó vẽ BA thanh RỜI, mỗi chặng reset về 0
   nên nhìn rời rạc, và không thể có MỘT vệt sáng chạy suốt. Đây là markup của mình nên
   không cần một dòng !important nào. */
.fmi-run-steps { display: flex; flex-direction: column; gap: 11px; }
.fmi-run-step { display: flex; align-items: center; gap: 11px; font-size: var(--text-base); }
.fmi-run-step__dot {
  width: 19px; height: 19px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--border-strong);
}
.fmi-run-step__label { font-weight: 500; }
.fmi-run-step__detail { font-size: var(--text-xs); color: var(--text-3); }
.fmi-run-step[data-state="done"] .fmi-run-step__dot {
  background: var(--success-soft); border-color: transparent; color: var(--success-fg);
}
.fmi-run-step[data-state="active"] .fmi-run-step__dot { border-color: var(--primary); }
.fmi-run-step[data-state="active"] .fmi-run-step__dot::after {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--primary);
  animation: fmi-pulse 1.2s ease-in-out infinite;
}
.fmi-run-step[data-state="active"] .fmi-run-step__label { font-weight: 600; }
.fmi-run-step[data-state="pending"] .fmi-run-step__label { color: var(--text-3); }

/* MỘT thanh liền chạy suốt run. Bề rộng = sự thật (--fmi-fill do vòng rAF ở screens.jsx ghi
   mỗi frame). Không đặt transition: transition KHÔNG BAO GIỜ chạy với giá trị từ var() mà
   còn NUỐT luôn cập nhật — đã đo, thanh đóng băng ở giá trị đầu. rAF tự nội suy. */
.fmi-runbar {
  height: 8px; margin-top: 16px; border-radius: var(--radius-full);
  background: var(--bg-sunken); overflow: hidden;
}
.fmi-runbar__fill {
  height: 100%; border-radius: var(--radius-full); background: var(--primary);
  width: var(--fmi-fill, 0%); position: relative; overflow: hidden;
}
/* Vệt sáng chạy BÊN TRONG phần đã đầy = "còn sống". Không đụng tới bề rộng ⇒ không nói dối
   con số. Nhờ nó, pha LLM (thanh đứng yên vì thật sự không có gì để đo) vẫn không nhìn như
   treo — mà agent chết thì vệt vẫn chạy, nên đây chỉ là nhịp sống của UI, không phải của agent. */
.fmi-runbar__fill::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  background-size: 70px 100%; background-repeat: no-repeat;
  animation: fmi-runbar-sheen 1.9s ease-in-out infinite;
}
@keyframes fmi-runbar-sheen {
  0%   { background-position: -70px 0; }
  100% { background-position: calc(100% + 70px) 0; }
}
.fmi-run-meta { display: flex; justify-content: space-between; margin-top: 9px; }
.fmi-run-logtoggle {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
  margin-top: 10px; font-size: var(--text-xs); font-weight: 600; color: var(--text-3);
}
.fmi-run-log {
  margin: 8px 0 0; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--bg-sunken); color: var(--text-2);
  overflow: auto; max-height: 140px; line-height: 1.7;
}

@media (prefers-reduced-motion: reduce) {      /* tôn trọng người tắt hiệu ứng */
  .fmi-runbar__fill::after,
  .fmi-run-step[data-state="active"] .fmi-run-step__dot::after { animation: none; }
}

/* Cài đặt → Lịch chạy: hai cột "Chu kỳ chạy" | "Kỳ phân tích".
   Trước đây là flex co giãn theo nội dung → mỗi agent có cụm chu kỳ rộng khác nhau
   (weekly thêm ô thứ, monthly thêm ô ngày) nên cột phải bắt đầu ở một x khác nhau,
   nhìn xuống 3 hàng thấy chữ so le. Grid cột cố định giữ mọi hàng thẳng nhau. */
.fmi-sched-grid {
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr) auto;   /* chu kỳ | kỳ | nút Lưu */
  gap: 16px;
  align-items: start;
}
.fmi-sched-grid__save { align-self: end; }
/* Cảnh báo chiếm trọn bề ngang dưới cả hàng — nó nói về QUAN HỆ giữa hai cột,
   nhét vào một cột là gợi ý sai rằng chỉ cột đó có vấn đề. */
.fmi-sched-warn {
  grid-column: 1 / -1;
  display: flex; gap: 7px; align-items: flex-start;
  margin-top: 2px; padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft, rgba(234, 179, 8, 0.12));
  color: var(--warning-fg, #92400e);
}
@media (max-width: 720px) {
  .fmi-sched-grid { grid-template-columns: minmax(0, 1fr); }
  .fmi-sched-grid__save { align-self: start; justify-self: start; }
}

/* Ô "Tín hiệu chính" (FMI_CompanySignalTable): tách chuỗi ';' thành bullet gọn, sát dòng
   để hàng bảng không giãn quá cao. Số/chỉ tiêu mở đầu đã bọc <strong> qua FMI_RENDER_BOLD. */
.signal-bullets { margin: 0; padding-left: 16px; list-style: disc; line-height: 1.5; }
.signal-bullets li { margin: 0 0 3px; }
.signal-bullets li:last-child { margin-bottom: 0; }
.signal-bullets li::marker { color: var(--text-3); }
.signal-bullets strong { color: var(--text-1); font-weight: 700; }
