/* Lavix — lớp thành phần dùng chung `.lx-*` (nạp ngay sau lavix-tokens.css, trước CSS của từng khu).
   Quy ước: CHỈ dùng token var(--lx-*), không mã màu cứng; mọi selector bắt đầu bằng một lớp .lx-* (không button{} / input{}
   toàn cục) nên khu chưa chuyển không bị đè. Tên: khối `.lx-x`, phần tử `.lx-x__y`, biến thể `.lx-x--z`, trạng thái qua
   thuộc tính chuẩn (:disabled, [aria-selected], [aria-checked], [aria-busy], [data-state]).
   API đầy đủ + ví dụ HTML: docs/superpowers/specs/2026-10-06-lavix-design-system.md; trang mẫu: public/dev-components.html. */

/* ===== Nút ===== */
.lx-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-sizing: border-box; height: var(--lx-h); min-width: 0; margin: 0; padding: 0 14px;
  border: 1px solid var(--lx-border); border-radius: var(--lx-radius-sm);
  background: var(--lx-surface); color: var(--lx-text);
  font: inherit; font-family: var(--lx-font); font-size: var(--lx-fs-13); font-weight: var(--lx-fw-semibold); line-height: 1;
  white-space: nowrap; text-decoration: none; cursor: pointer; user-select: none;
  transition: background var(--lx-transition), border-color var(--lx-transition), color var(--lx-transition);
}
.lx-btn:hover { background: var(--lx-surface-hover); border-color: var(--lx-border-strong); }
.lx-btn:focus-visible { outline: 2px solid var(--lx-focus); outline-offset: 2px; }
.lx-btn:disabled, .lx-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; pointer-events: none; }
.lx-btn[aria-busy="true"] { cursor: progress; opacity: .75; }
.lx-btn--primary { background: var(--lx-primary); border-color: var(--lx-primary); color: var(--lx-primary-fg); }
.lx-btn--primary:hover { background: var(--lx-primary-hover); border-color: var(--lx-primary-hover); }
.lx-btn--primary:active { background: var(--lx-primary-active); border-color: var(--lx-primary-active); }
/* Nút xoá / nguy hiểm: CHỈ khác màu chữ (quy tắc AGENTS.md) — cùng nền, viền, cỡ với nút thường. */
.lx-btn--danger { color: var(--lx-bad-fg); }
.lx-btn--danger:hover { background: var(--lx-bad-bg); border-color: var(--lx-bad-border); }
.lx-btn--ghost { background: transparent; border-color: transparent; color: var(--lx-muted); }
.lx-btn--ghost:hover { background: var(--lx-surface-hover); border-color: transparent; color: var(--lx-text); }
.lx-btn--sm { height: var(--lx-h-sm); padding: 0 10px; font-size: var(--lx-fs-12); }
.lx-btn--lg { height: var(--lx-h-lg); padding: 0 18px; font-size: var(--lx-fs-14); }
.lx-btn--icon { width: var(--lx-h); padding: 0; }
.lx-btn--icon.lx-btn--sm { width: var(--lx-h-sm); }
.lx-btn--icon.lx-btn--lg { width: var(--lx-h-lg); }
.lx-btn--block { display: flex; width: 100%; }

/* ===== Ô nhập / chọn / vùng chữ ===== */
.lx-input, .lx-select, .lx-textarea {
  box-sizing: border-box; width: 100%; min-width: 0; height: var(--lx-h); margin: 0; padding: 0 10px;
  border: 1px solid var(--lx-border); border-radius: var(--lx-radius-sm);
  background: var(--lx-surface); color: var(--lx-text);
  font: inherit; font-family: var(--lx-font); font-size: var(--lx-fs-13); line-height: var(--lx-lh);
  transition: border-color var(--lx-transition), box-shadow var(--lx-transition);
}
.lx-textarea { height: auto; min-height: 88px; padding: 8px 10px; resize: vertical; }
.lx-select { padding-right: 6px; cursor: pointer; }
.lx-input::placeholder, .lx-textarea::placeholder { color: var(--lx-subtle); }
.lx-input:hover, .lx-select:hover, .lx-textarea:hover { border-color: var(--lx-border-strong); }
.lx-input:focus, .lx-select:focus, .lx-textarea:focus { outline: none; border-color: var(--lx-primary); box-shadow: var(--lx-focus-ring); }
.lx-input:disabled, .lx-select:disabled, .lx-textarea:disabled, .lx-input[readonly] { background: var(--lx-surface-soft); color: var(--lx-muted); cursor: not-allowed; }
.lx-input[aria-invalid="true"], .lx-select[aria-invalid="true"], .lx-textarea[aria-invalid="true"] { border-color: var(--lx-bad-fg); }
.lx-input--sm, .lx-select--sm { height: var(--lx-h-sm); font-size: var(--lx-fs-12); }
.lx-input--lg, .lx-select--lg { height: var(--lx-h-lg); font-size: var(--lx-fs-14); }
.lx-input--num { text-align: right; font-variant-numeric: tabular-nums; }

/* ===== Trường (nhãn + ô + gợi ý / lỗi) ===== */
.lx-field { display: grid; align-content: start; gap: 6px; min-width: 0; margin: 0; }
.lx-field__label { color: var(--lx-text); font-size: var(--lx-fs-12); font-weight: var(--lx-fw-semibold); line-height: 1.4; }
.lx-field__hint { color: var(--lx-muted); font-size: var(--lx-fs-12); line-height: 1.45; }
.lx-field__error { color: var(--lx-bad-fg); font-size: var(--lx-fs-12); line-height: 1.45; }
.lx-field--inline { display: flex; align-items: center; gap: var(--lx-space-2); }
.lx-field--inline .lx-field__label { flex: 0 0 auto; }

/* Bố cục nhỏ: hàng ô / nút cùng chiều cao, cột xếp dọc, lưới trường. */
.lx-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--lx-space-2); min-width: 0; }
.lx-row > .lx-input, .lx-row > .lx-select { width: auto; flex: 1 1 160px; }
.lx-stack { display: grid; gap: var(--lx-space-3); min-width: 0; }
.lx-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--lx-space-3) var(--lx-space-4); }

/* ===== Thẻ ===== */
.lx-card {
  box-sizing: border-box; min-width: 0; padding: var(--lx-space-5);
  border: 1px solid var(--lx-border); border-radius: var(--lx-radius);
  background: var(--lx-surface); color: var(--lx-text);
}
.lx-card--raised { box-shadow: var(--lx-shadow-sm); }
.lx-card--flush { padding: 0; overflow: hidden; }
.lx-card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--lx-space-2) var(--lx-space-3); margin: 0 0 var(--lx-space-3); }
.lx-card__title { margin: 0; color: var(--lx-text); font-size: var(--lx-fs-16); font-weight: var(--lx-fw-semibold); line-height: 1.35; }
.lx-card__sub { margin: 2px 0 0; color: var(--lx-muted); font-size: var(--lx-fs-12); }
.lx-card__foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--lx-space-2); margin-top: var(--lx-space-4); }

/* ===== Nhãn trạng thái ===== */
.lx-badge {
  display: inline-flex; align-items: center; gap: 5px; box-sizing: border-box; height: 22px; padding: 0 8px;
  border: 1px solid var(--lx-idle-border); border-radius: var(--lx-radius-pill);
  background: var(--lx-idle-bg); color: var(--lx-idle-fg);
  font-family: var(--lx-font); font-size: var(--lx-fs-12); font-weight: var(--lx-fw-semibold); line-height: 1; white-space: nowrap; vertical-align: middle;
}
.lx-badge--ok { background: var(--lx-ok-bg); color: var(--lx-ok-fg); border-color: var(--lx-ok-border); }
.lx-badge--warn { background: var(--lx-warn-bg); color: var(--lx-warn-fg); border-color: var(--lx-warn-border); }
.lx-badge--bad { background: var(--lx-bad-bg); color: var(--lx-bad-fg); border-color: var(--lx-bad-border); }
.lx-badge--info { background: var(--lx-info-bg); color: var(--lx-info-fg); border-color: var(--lx-info-border); }
.lx-badge--idle { background: var(--lx-idle-bg); color: var(--lx-idle-fg); border-color: var(--lx-idle-border); }
.lx-badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ===== Bảng ===== */
.lx-table-wrap { min-width: 0; overflow: auto; border: 1px solid var(--lx-border); border-radius: var(--lx-radius); background: var(--lx-surface); }
.lx-table { width: 100%; border-collapse: separate; border-spacing: 0; color: var(--lx-text); font-family: var(--lx-font); font-size: var(--lx-fs-13); }
.lx-table th, .lx-table td { padding: 10px 12px; border-bottom: 1px solid var(--lx-border); text-align: left; vertical-align: middle; }
.lx-table th { background: var(--lx-surface-soft); color: var(--lx-muted); font-size: var(--lx-fs-12); font-weight: var(--lx-fw-semibold); white-space: nowrap; }
.lx-table tbody tr:hover > td { background: var(--lx-row-hover); }
.lx-table tbody tr:last-child > td { border-bottom: 0; }
.lx-table .lx-table__num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lx-table .lx-table__actions { width: 1%; text-align: right; white-space: nowrap; }
.lx-table--sticky thead th { position: sticky; top: 0; z-index: var(--lx-z-sticky); }
.lx-table--compact th, .lx-table--compact td { padding: 6px 10px; }

/* ===== Khung danh sách dài (chủ dự án 7/10, public/paged-list.js) =====
   Danh sách có thể dài nằm trong khung cố định chiều cao, cuộn trong khung, đầu bảng dính; cuối khung là chân
   "⬇️ Tải thêm" / "Đã hết · N" / lỗi + "🔁 Thử lại". Đặt --lx-list-frame-h trên khung để đổi chiều cao. */
.lx-list-frame { box-sizing: border-box; max-height: var(--lx-list-frame-h, min(70vh, 760px)); overflow: auto; overscroll-behavior: contain; min-width: 0; }
.lx-list-frame thead th { position: sticky; top: 0; z-index: var(--lx-z-sticky); background-color: var(--lx-surface-soft); }
.lx-list-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--lx-space-2); padding: var(--lx-space-3) var(--lx-space-2); color: var(--lx-muted); font-size: var(--lx-fs-12); text-align: center; }
.lx-list-footer[hidden] { display: none; }
.lx-list-footer__error { color: var(--lx-bad-fg); }

/* ===== Hộp thoại =====
   Hộp cao theo nội dung (không kéo giãn) → chân có nút nằm NGAY dưới nội dung; nội dung dài thì chỉ thân cuộn, đầu / chân đứng yên. */
.lx-modal {
  position: fixed; inset: 0; z-index: var(--lx-z-modal);
  display: grid; place-items: center; padding: var(--lx-space-4);
  background: var(--lx-overlay);
}
.lx-modal[hidden] { display: none; }
.lx-modal__dialog {
  box-sizing: border-box; display: flex; flex-direction: column; width: min(560px, 100%); max-height: calc(100dvh - 32px);
  border: 1px solid var(--lx-border); border-radius: var(--lx-radius-lg);
  background: var(--lx-surface); color: var(--lx-text); box-shadow: var(--lx-shadow-modal); overflow: hidden;
  font-family: var(--lx-font); font-size: var(--lx-fs-13); line-height: var(--lx-lh);
}
.lx-modal--sm .lx-modal__dialog { width: min(420px, 100%); }
.lx-modal--lg .lx-modal__dialog { width: min(760px, 100%); }
.lx-modal--xl .lx-modal__dialog { width: min(980px, 100%); }
.lx-modal__head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: var(--lx-space-3); padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--lx-border); }
.lx-modal__title { margin: 0; min-width: 0; color: var(--lx-text); font-size: var(--lx-fs-16); font-weight: var(--lx-fw-semibold); line-height: 1.35; }
.lx-modal__body { flex: 0 1 auto; min-height: 0; overflow: auto; padding: var(--lx-space-5); }
.lx-modal__foot { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--lx-space-2); padding: 12px 20px; border-top: 1px solid var(--lx-border); background: var(--lx-surface); }
.lx-modal__foot .lx-save { margin-right: auto; }

/* ===== Thẻ chuyển mục (tabs) ===== */
.lx-tabs { display: flex; gap: 2px; min-width: 0; overflow-x: auto; border-bottom: 1px solid var(--lx-border); scrollbar-width: thin; }
.lx-tab {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; height: var(--lx-h); margin: 0 0 -1px; padding: 0 12px;
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--lx-muted);
  font: inherit; font-family: var(--lx-font); font-size: var(--lx-fs-13); font-weight: var(--lx-fw-semibold); white-space: nowrap; text-decoration: none; cursor: pointer;
}
.lx-tab:hover { color: var(--lx-text); }
.lx-tab:focus-visible { outline: 2px solid var(--lx-focus); outline-offset: -2px; }
.lx-tab[aria-selected="true"], .lx-tab.is-active { color: var(--lx-primary); border-bottom-color: var(--lx-primary); }
/* Dạng nút gộp (bộ lọc ngắn, chọn chế độ). */
.lx-tabs--pills { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--lx-border); border-radius: var(--lx-radius-sm); background: var(--lx-surface-soft); }
.lx-tabs--pills .lx-tab { height: calc(var(--lx-h) - 6px); margin: 0; padding: 0 10px; border: 0; border-radius: 5px; }
.lx-tabs--pills .lx-tab[aria-selected="true"], .lx-tabs--pills .lx-tab.is-active { background: var(--lx-surface); color: var(--lx-text); box-shadow: var(--lx-shadow-sm); }

/* ===== Thanh công cụ (lọc / tìm / hành động đầu bảng) ===== */
.lx-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--lx-space-2); min-width: 0; }
.lx-toolbar > .lx-input, .lx-toolbar > .lx-select { width: auto; min-width: 140px; }
.lx-toolbar__grow { flex: 1 1 220px; min-width: 0; }
.lx-toolbar__spacer { flex: 1 1 auto; }

/* ===== Thông báo trong trang ===== */
.lx-notice {
  display: flex; align-items: flex-start; gap: 10px; box-sizing: border-box; padding: 10px 12px;
  border: 1px solid var(--lx-info-border); border-radius: var(--lx-radius-sm);
  background: var(--lx-info-bg); color: var(--lx-text); font-size: var(--lx-fs-13); line-height: var(--lx-lh);
}
.lx-notice--ok { background: var(--lx-ok-bg); border-color: var(--lx-ok-border); }
.lx-notice--warn { background: var(--lx-warn-bg); border-color: var(--lx-warn-border); }
.lx-notice--bad { background: var(--lx-bad-bg); border-color: var(--lx-bad-border); }
.lx-notice--info { background: var(--lx-info-bg); border-color: var(--lx-info-border); }
.lx-notice__title { display: block; margin: 0 0 2px; font-weight: var(--lx-fw-semibold); }
.lx-notice__body { flex: 1 1 auto; min-width: 0; }

/* ===== Thông báo nổi (toast) ===== */
.lx-toast-stack { position: fixed; right: var(--lx-space-4); bottom: var(--lx-space-4); z-index: var(--lx-z-toast); display: grid; gap: var(--lx-space-2); justify-items: end; pointer-events: none; }
.lx-toast {
  display: flex; align-items: center; gap: 10px; box-sizing: border-box; min-width: 220px; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px;
  border-left: 4px solid var(--lx-info-fg); border-radius: var(--lx-radius-sm);
  background: var(--lx-toast-bg); color: var(--lx-toast-fg); box-shadow: var(--lx-shadow-md);
  font-family: var(--lx-font); font-size: var(--lx-fs-13); line-height: 1.4; pointer-events: auto;
  animation: lx-toast-in .18s ease-out;
}
.lx-toast--ok { border-left-color: var(--lx-ok-border); }
.lx-toast--warn { border-left-color: var(--lx-warn-border); }
.lx-toast--bad { border-left-color: var(--lx-bad-border); }
@keyframes lx-toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== Trạng thái tự lưu: Đang lưu… / Đã lưu / lỗi + Thử lại =====
   <span class="lx-save" data-state="saving|saved|error" role="status"><span class="lx-save__text">Đang lưu…</span>
   <button class="lx-btn lx-btn--sm lx-save__retry">🔁 Thử lại</button></span>. Không có data-state → ẩn. */
.lx-save { display: inline-flex; align-items: center; gap: 6px; min-height: 20px; color: var(--lx-muted); font-family: var(--lx-font); font-size: var(--lx-fs-12); line-height: 1.3; }
.lx-save:not([data-state]), .lx-save[data-state=""], .lx-save[data-state="idle"] { visibility: hidden; }
.lx-save[data-state="saving"]::before { content: ""; width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: lx-spin .7s linear infinite; }
.lx-save[data-state="saved"] { color: var(--lx-ok-fg); }
.lx-save[data-state="saved"]::before { content: "✓"; font-weight: var(--lx-fw-bold); }
.lx-save[data-state="error"] { color: var(--lx-bad-fg); }
.lx-save:not([data-state="error"]) .lx-save__retry { display: none; }
.lx-save__retry[hidden] { display: none; }
@keyframes lx-spin { to { transform: rotate(360deg); } }

/* ===== Trống ===== */
.lx-empty { display: grid; justify-items: center; gap: 6px; box-sizing: border-box; padding: var(--lx-space-8) var(--lx-space-4); border: 1px dashed var(--lx-border-strong); border-radius: var(--lx-radius); color: var(--lx-muted); font-size: var(--lx-fs-13); text-align: center; }
.lx-empty__icon { font-size: var(--lx-fs-24); line-height: 1; }
.lx-empty__title { margin: 0; color: var(--lx-text); font-size: var(--lx-fs-14); font-weight: var(--lx-fw-semibold); }
.lx-empty__text { margin: 0; max-width: 46ch; }

/* ===== Công tắc bật / tắt (như màn Quảng cáo) =====
   <button class="lx-switch" role="switch" aria-checked="true" aria-label="…"></button> hoặc <input type="checkbox" class="lx-switch">.
   Đang gửi lệnh: aria-busy="true". */
.lx-switch {
  position: relative; display: inline-block; flex: 0 0 36px; box-sizing: border-box; width: 36px; height: 20px; margin: 0; padding: 0;
  border: 0; border-radius: var(--lx-radius-pill); background: var(--lx-switch-off);
  appearance: none; -webkit-appearance: none; cursor: pointer; vertical-align: middle; transition: background var(--lx-transition);
}
.lx-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--lx-surface); box-shadow: var(--lx-shadow-sm); transition: left var(--lx-transition); }
.lx-switch[aria-checked="true"], .lx-switch:checked { background: var(--lx-primary); }
.lx-switch[aria-checked="true"]::after, .lx-switch:checked::after { left: 18px; }
.lx-switch:focus-visible { outline: 2px solid var(--lx-focus); outline-offset: 2px; }
.lx-switch:disabled { opacity: .45; cursor: not-allowed; }
.lx-switch[aria-busy="true"] { opacity: .6; cursor: progress; }
.lx-switch[aria-busy="true"]::after { animation: lx-pulse .8s ease-in-out infinite alternate; }
@keyframes lx-pulse { to { transform: scale(.8); } }
.lx-switch-label { display: inline-flex; align-items: center; gap: var(--lx-space-2); color: var(--lx-text); font-size: var(--lx-fs-13); cursor: pointer; }

/* ===== Tiện ích ===== */
.lx-muted { color: var(--lx-muted); }
.lx-num { font-variant-numeric: tabular-nums; }
.lx-sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 560px) {
  .lx-modal { padding: var(--lx-space-2); align-items: end; }
  .lx-modal__dialog, .lx-modal--sm .lx-modal__dialog, .lx-modal--lg .lx-modal__dialog, .lx-modal--xl .lx-modal__dialog { width: 100%; max-height: calc(100dvh - 16px); }
  .lx-modal__body { padding: var(--lx-space-4); }
  .lx-modal__foot { padding: 10px 16px; }
  .lx-toast-stack { left: var(--lx-space-2); right: var(--lx-space-2); bottom: var(--lx-space-2); justify-items: stretch; }
  .lx-toast { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  .lx-btn, .lx-input, .lx-select, .lx-textarea, .lx-switch, .lx-switch::after, .lx-toast { transition: none; animation: none; }
  .lx-save[data-state="saving"]::before { animation-duration: 2s; }
}
