/* ============================================================================
   com_chessresults — bộ giao diện dùng chung (cr-ui)
   v1.0 · 28/08/2026

   MỌI quy tắc đều nằm trong .cr-ui. View nào chưa gắn class đó thì KHÔNG bị
   ảnh hưởng một chút nào — nhờ vậy có thể đổi dần từng view mà không sợ vỡ.

   Cách dùng trong tmpl:
       \Joomla\Component\Chessresults\Site\Helper\UiHelper::css();
       <div class="... cr-ui"> … </div>
   ============================================================================ */

.cr-ui {
    /* — kích thước — */
    --cr-h: 30px;              /* chiều cao MỌI nút, ô nhập, ô chọn */
    --cr-row: 30px;            /* chiều cao một dòng dữ liệu (mật độ Vừa) */
    --cr-r: 6px;               /* bo góc nút, ô nhập */
    --cr-r-card: 10px;         /* bo góc thẻ, khung bảng */
    --cr-fs: 13px;             /* chữ trên nút và trong ô dữ liệu */
    --cr-fs-th: 11px;          /* tiêu đề cột */
    --cr-gap: 8px;

    /* — nền và chữ — */
    --cr-ground: #f6f7f9;
    --cr-surface: #ffffff;
    --cr-surface-2: #eff2f6;
    --cr-surface-3: #f9fafb;
    --cr-ink: #18222e;
    --cr-ink-2: #4e5c6b;
    --cr-ink-3: #7b8896;
    --cr-line: #dfe4ea;
    --cr-line-strong: #c6ced7;
    --cr-accent: #2f5070;
    --cr-accent-soft: #e9eff6;

    /* — màu theo HÀNH ĐỘNG (không theo view) — */
    --cr-view: #2c6fbb;        /* xem, mở, điều hướng */
    --cr-new: #1f9d57;         /* tạo mới, xuất bản, lưu */
    --cr-edit: #b87400;        /* sửa, khoá */
    --cr-del: #c6362f;         /* xoá */
    --cr-import: #0e8c9a;      /* nạp dữ liệu vào */
    --cr-export: #5b54c7;      /* đưa dữ liệu ra */
    --cr-neutral: #5b6875;     /* việc phụ */

    /* — trạng thái — */
    --cr-ok: #1f9d57;
    --cr-warn: #b87400;
    --cr-off: #8a939e;

    color: var(--cr-ink);
}

/* Mật độ dòng: Thoáng / Vừa / Gọn */
.cr-ui[data-density="loose"]   { --cr-row: 38px; }
.cr-ui[data-density="compact"] { --cr-row: 24px; --cr-fs: 12.5px; }

/* ----------------------------------------------------------------- KHUNG -- */

/* KHÔNG dùng overflow:hidden ở đây — nó biến thẻ thành khung cuộn và làm tiêu đề cột
   position:sticky mất tác dụng. Bo góc bằng chính phần đầu thẻ. */
.cr-ui .cr-card {
    background: var(--cr-surface);
    border: 1px solid var(--cr-line);
    border-radius: var(--cr-r-card);
}

.cr-ui .cr-card-head {
    border-radius: var(--cr-r-card) var(--cr-r-card) 0 0;
    display: flex;
    align-items: center;
    gap: var(--cr-gap);
    flex-wrap: wrap;
    padding: 9px 14px;
    background: var(--cr-accent);
    color: #fff;
}

/* Template KHÔNG nạp utility .ms-auto của Bootstrap (đã đo: margin-left = 0px),
   nên phải tự đẩy nhóm cuối cùng sang phải. :not(:first-child) để đầu thẻ chỉ có
   mỗi tiêu đề thì tiêu đề không bị đẩy đi. */
.cr-ui .cr-card-head > :last-child:not(:first-child) { margin-left: auto; }

.cr-ui .cr-card-head .cr-title {
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: .01em;
    margin: 0;
    color: #fff;
}

.cr-ui .cr-card-body { padding: 14px; }

/* Thanh công cụ: lọc bên TRÁI, hành động bên PHẢI */
.cr-ui .cr-toolbar {
    display: flex;
    align-items: center;
    gap: var(--cr-gap);
    flex-wrap: wrap;
    padding: 8px 10px;
    margin-bottom: 12px;
    background: var(--cr-surface-3);
    border: 1px solid var(--cr-line);
    border-radius: 8px;
}
.cr-ui .cr-toolbar .cr-sep { flex: 1 1 auto; }
.cr-ui .cr-toolbar label { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--cr-ink-2); }

/* ------------------------------------------------------------------- NÚT -- */

.cr-ui .crb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: var(--cr-h);
    min-height: var(--cr-h);
    padding: 0 12px;
    border: 0;
    border-radius: var(--cr-r);
    font-size: var(--cr-fs);
    font-weight: 600;
    line-height: 1;
    text-transform: none;      /* ghi đè template T4 (uppercase) */
    letter-spacing: 0;
    white-space: nowrap;
    color: #fff;
    background: var(--cr-neutral);
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
    transition: filter .12s ease, transform .12s ease;
}
.cr-ui .crb:hover  { filter: brightness(1.08); color: #fff; text-decoration: none; }
.cr-ui .crb:active { transform: translateY(1px); }
.cr-ui .crb:focus-visible { outline: 2px solid var(--cr-accent); outline-offset: 2px; }
.cr-ui .crb[disabled], .cr-ui .crb.disabled { opacity: .5; pointer-events: none; }

.cr-ui .crb-view    { background: var(--cr-view); }
.cr-ui .crb-new     { background: var(--cr-new); }
.cr-ui .crb-edit    { background: var(--cr-edit); }
.cr-ui .crb-del     { background: var(--cr-del); }
.cr-ui .crb-import  { background: var(--cr-import); }
.cr-ui .crb-export  { background: var(--cr-export); }
.cr-ui .crb-neutral { background: var(--cr-neutral); }

.cr-ui .crb-ghost {
    background: transparent;
    color: var(--cr-ink-2);
    box-shadow: inset 0 0 0 1px var(--cr-line-strong);
}
.cr-ui .crb-ghost:hover { background: var(--cr-surface-2); color: var(--cr-ink); }

/* Ngoại lệ có kiểm soát: nút CHỌN trong hộp thoại, có thêm dòng giải thích nhỏ.
   Không ép 30px được vì 2 dòng chữ, nhưng vẫn giữ đúng bảng màu. */
.cr-ui .crb-2dong {
    height: auto;
    min-height: 30px;
    flex-direction: column;
    gap: 1px;
    padding: 6px 12px;
    line-height: 1.25;
    text-align: center;
}
.cr-ui .crb-2dong small { font-size: 11px; font-weight: 500; opacity: .85; }

/* Một icon SVG trong nút phải cao bằng ký tự của nút cạnh nó, kẻo trông như bị teo. */
.cr-ui .crb-icon svg { width: 17px; height: 17px; display: block; flex: 0 0 auto; }
.cr-ui table.crt .crb-icon svg { width: 15px; height: 15px; }

/* Nút chỉ icon, vuông 30×30 — dùng cho cột Thao tác */
.cr-ui .crb-icon { width: var(--cr-h); padding: 0; font-size: 14px; vertical-align: middle; }

/* Trong bảng thì nhỏ lại 24×24, kẻo nút cao bằng dòng sẽ thành một dải màu liền */
/* Quy tắc .cr-ui table.crt .crb đặt padding 0 10px và đặc hiệu hơn .crb-icon, nên nút icon
   trong bảng chỉ còn 4px cho hình -> phải gỡ padding ở đúng mức đặc hiệu đó. */
.cr-ui table.crt .crb-icon,
.cr-ui .wb-sheet-table .crb-icon { height: 24px; min-height: 24px; width: 24px; padding: 0; font-size: 13px; }
/* Mọi nút nằm TRONG bảng đều 24px, không riêng nút icon */
.cr-ui table.crt .crb,
.cr-ui .wb-sheet-table .crb { height: 24px; min-height: 24px; font-size: 12px; padding: 0 10px; }
.cr-ui table.crt td .form-check-input { margin: 0; vertical-align: middle; }
.cr-ui table.crt th .form-check-input,
.cr-ui table.crt th input[type="checkbox"] { margin: 0; vertical-align: middle; }

/* Nút trên nền đậm (trong .cr-card-head) */
.cr-ui .cr-card-head .crb-ghost {
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .45);
}
.cr-ui .cr-card-head .crb-ghost:hover { background: rgba(255, 255, 255, .14); color: #fff; }

/* Bootstrap còn sót lại trong vùng cr-ui: ép cùng chiều cao, bỏ chữ hoa */
.cr-ui .btn {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
    .cr-ui .crb { transition: none; }
}

/* -------------------------------------------------------------- Ô NHẬP --- */

.cr-ui .form-control,
.cr-ui .form-select,
.cr-ui .cr-fld {
    height: var(--cr-h);
    min-height: var(--cr-h);
    padding: 0 10px;
    font-size: var(--cr-fs);
    line-height: 1.2;
    border: 1px solid var(--cr-line-strong);
    border-radius: var(--cr-r);
    background-color: var(--cr-surface);
    color: var(--cr-ink);
    box-sizing: border-box;
}
.cr-ui .form-select { padding-right: 28px; }
.cr-ui textarea.form-control { height: auto; min-height: 60px; padding: 6px 10px; }
.cr-ui .form-control:focus,
.cr-ui .form-select:focus {
    border-color: var(--cr-accent);
    box-shadow: 0 0 0 3px var(--cr-accent-soft);
    outline: 0;
}
/* Template đặt .form-check-input{position:absolute;left:0} -> nút tròn/ô tích đè lên nhãn.
   Trả về dòng chảy bình thường. Kèm .form-check thành inline-flex, nếu không ô tích
   sẽ rơi xuống DÒNG RIÊNG khi khung hẹp (gặp ở chessresultsimport). */
.cr-ui .form-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding-left: 0;
    margin: 0;
    min-height: 0;
}
.cr-ui .form-check-label { margin: 0; white-space: nowrap; }
.cr-ui .form-check-input {
    position: static;
    float: none;
    width: 15px;
    height: 15px;
    margin: 0;
    cursor: pointer;
}
.cr-ui .cr-fld-sm { width: auto; min-width: 130px; }

/* ----------------------------------------------------------------- BẢNG -- */

/* Khung bảng KHÔNG cắt chiều cao: bảng dài bao nhiêu hiện bấy nhiêu, không có thanh
   cuộn riêng — cuộn bằng chính trang. Nhờ không có tổ tiên overflow, tiêu đề cột
   position:sticky bám theo MÉP TRÊN CỦA MÀN HÌNH khi cuộn trang. */
.cr-ui .cr-scroll {
    max-height: none;
    overflow: visible;
    border: 1px solid var(--cr-line);
    border-radius: 8px;
    background: var(--cr-surface);
}
/* overflow:visible nên phải tự bo góc ô đầu/cuối, kẻo nền tiêu đề vuông chọc ra ngoài viền */
.cr-ui .cr-scroll > table.crt thead th:first-child { border-top-left-radius: 7px; }
.cr-ui .cr-scroll > table.crt thead th:last-child  { border-top-right-radius: 7px; }
.cr-ui .cr-scroll > table.crt tbody tr:last-child > td { border-bottom: 0; }

/* Bảng RỘNG (nhiều cột) mới thêm class này để cuộn ngang trong khung.
   Đánh đổi: có tổ tiên overflow thì tiêu đề cột hết bám theo màn hình. */
.cr-ui .cr-scroll-x { overflow-x: auto; }
/* Bảng NHIỀU CỘT: giữ tiêu đề bám khi bảng còn vừa khung, chỉ cuộn ngang khi
   bảng THỰC SỰ rộng hơn khung. Bề rộng khung do template quyết định (~1090px) chứ
   không theo bề rộng màn hình, nên đo bằng JS (cr-ui.js gắn .cr-need-x) thay vì
   media query — trước đây dùng max-width:1200px làm bảng lòi hẳn ra ngoài trang
   trên màn hình rộng. */
.cr-ui .cr-scroll-mx.cr-need-x { overflow-x: auto; min-width: 0; }
/* Khung nội dung của template admin (Atum) là flex item với min-width:auto, nên một
   bảng rộng (thường do hàng ô lọc) kéo phình cả khung ra ngoài màn hình thay vì để
   bảng tự cuộn. Cho phép khung co lại thì .cr-need-x ở trên mới phát huy tác dụng. */
body.admin .container-main { min-width: 0; }
@media (max-width: 1200px) { .cr-ui .cr-scroll-mx { overflow-x: auto; } }

/* Vài bảng để ô tích ở <thead> bằng thẻ <td> thay vì <th> */
.cr-ui table.crt thead td {
    position: sticky;
    top: var(--cr-sticky-top, 0px);
    z-index: 2;
    height: 32px;
    padding: 0 10px;
    background: var(--cr-surface-3);
    border-bottom: 1px solid var(--cr-line-strong);
}

.cr-ui table.crt {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--cr-fs);
    font-variant-numeric: tabular-nums;
    background: var(--cr-surface);
}

.cr-ui table.crt th {
    position: sticky;
    top: var(--cr-sticky-top, 0px);
    z-index: 2;
    height: 32px;
    padding: 0 10px;
    text-align: left;
    font-size: var(--cr-fs-th);
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--cr-ink-3);
    white-space: nowrap;
    background: var(--cr-surface-3);
    border-bottom: 1px solid var(--cr-line-strong);
}

.cr-ui table.crt td {
    height: var(--cr-row);
    padding: 0 10px;
    border-bottom: 1px solid var(--cr-line);
    color: var(--cr-ink);
    white-space: nowrap;
    vertical-align: middle;
}

.cr-ui table.crt tbody tr:nth-child(even) > td { background: rgba(239, 242, 246, .55); }
/* Khi có phân trang thì vằn phải tính theo dòng ĐANG HIỆN, không theo thứ tự trong DOM —
   nếu không, ẩn bớt dòng là vằn loang lổ. JS gắn class .cr-zebra cho dòng chẵn đang hiện. */
.cr-ui table.crt[data-cr-pager] tbody tr:nth-child(even) > td { background: transparent; }
.cr-ui table.crt tbody tr.cr-zebra > td { background: rgba(239, 242, 246, .55); }
.cr-ui table.crt tbody tr.cr-lastvis > td { border-bottom: 0; }
.cr-ui table.crt tbody tr:hover > td { background: var(--cr-accent-soft); }
.cr-ui table.crt.cr-nozebra tbody tr:nth-child(even) > td { background: transparent; }

.cr-ui table.crt td.cr-num, .cr-ui table.crt th.cr-num { text-align: right; }
.cr-ui table.crt td.cr-mid, .cr-ui table.crt th.cr-mid { text-align: center; }
.cr-ui table.crt td.cr-act {
    text-align: right;
    padding-right: 8px;
    white-space: nowrap;
}
.cr-ui table.crt td.cr-act .crb + .crb { margin-left: 4px; }
.cr-ui table.crt code {
    font-size: 12px;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--cr-surface-2);
    border: 1px solid var(--cr-line);
    color: var(--cr-ink-2);
}
.cr-ui table.crt td.cr-wrap { white-space: normal; }

/* ---------------------------------------------------------- PHÂN TRANG --- */
/* Nút số trong vòng tròn, cùng kiểu với view=medalsmanage (32px, bo tròn hẳn). */

.cr-ui .cr-pager-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 2px 0;
    font-size: 12.5px;
    color: var(--cr-ink-3);
}
.cr-ui .cr-pager-info b { color: var(--cr-ink-2); font-variant-numeric: tabular-nums; }
.cr-ui .cr-pager-nums {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin: 0 auto;
}
.cr-ui .cr-pager-per { display: inline-flex; align-items: center; gap: 6px; }
.cr-ui .cr-pager-per select { height: 26px; padding: 0 6px; font-size: 12.5px; }
.cr-ui .cr-pager-gap { padding: 0 2px; color: var(--cr-ink-3); }

.cr-ui .cr-pg {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--cr-line-strong);
    border-radius: 50%;
    background: var(--cr-surface);
    color: var(--cr-view);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.cr-ui .cr-pg:hover:not(:disabled):not(.is-on) { background: var(--cr-accent-soft); }
.cr-ui .cr-pg:focus-visible { outline: 2px solid var(--cr-accent); outline-offset: 2px; }
.cr-ui .cr-pg.is-on {
    background: var(--cr-accent);
    border-color: var(--cr-accent);
    color: #fff;
    cursor: default;
}
.cr-ui .cr-pg:disabled { opacity: .35; cursor: default; }
@media (prefers-reduced-motion: reduce) { .cr-ui .cr-pg { transition: none; } }

/* Các view cũ (medals, tournamentsmanage, clubs) đã tự dựng phân trang bằng
   .pagination của Bootstrap. Khoác cho nó đúng bộ nút tròn ở trên, KHỎI phải
   sửa JS của từng view. */
.cr-ui .pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
}
.cr-ui .pagination .page-item { margin: 0; }
.cr-ui .pagination .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--cr-line-strong);
    border-radius: 50%;
    background: var(--cr-surface);
    color: var(--cr-view);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-decoration: none;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.cr-ui .pagination .page-link:hover { background: var(--cr-accent-soft); }
.cr-ui .pagination .page-link:focus-visible { outline: 2px solid var(--cr-accent); outline-offset: 2px; }
.cr-ui .pagination .page-item.active .page-link {
    background: var(--cr-accent);
    border-color: var(--cr-accent);
    color: #fff;
}
.cr-ui .pagination .page-item.disabled .page-link { opacity: .35; }
@media (prefers-reduced-motion: reduce) { .cr-ui .pagination .page-link { transition: none; } }

/* Hàng thứ 2 của thead = ô lọc theo cột. Phải dính NGAY DƯỚI hàng tiêu đề,
   nếu để top:0 như hàng đầu thì hai hàng chồng lên nhau. */
.cr-ui table.crt thead tr.cr-filters th {
    top: 32px;
    height: auto;
    padding: 4px 6px;
    background: var(--cr-surface);
    border-bottom: 1px solid var(--cr-line);
}
.cr-ui table.crt thead tr.cr-filters .form-control,
.cr-ui table.crt thead tr.cr-filters .form-select {
    height: 26px;
    font-size: 12px;
    padding: 0 7px;
}
/* <select> tự nong theo lựa chọn DÀI NHẤT và kéo giãn cả cột -> phải ép về bề rộng ô.
   min-width:0 là mấu chốt, thiếu nó thì width:100% vẫn không co lại được. */
.cr-ui table.crt thead tr.cr-filters .form-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding-right: 18px;
    text-overflow: ellipsis;
}

/* Dòng đếm phía trên bảng */
.cr-ui .cr-count {
    font-size: 12.5px;
    color: var(--cr-ink-3);
    padding: 0 2px 6px;
}
.cr-ui .cr-count b { color: var(--cr-ink-2); }

/* ----------------------------------------------------------------- CHIP -- */

.cr-ui .cr-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 20px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    border: 1px solid;
    background: transparent;
}
.cr-ui .cr-chip-on   { color: var(--cr-ok);   border-color: rgba(31, 157, 87, .42);  background: rgba(31, 157, 87, .11); }
.cr-ui .cr-chip-off  { color: var(--cr-off);  border-color: rgba(138, 147, 158, .42); background: rgba(138, 147, 158, .11); }
.cr-ui .cr-chip-lock { color: var(--cr-warn); border-color: rgba(184, 116, 0, .42);   background: rgba(184, 116, 0, .11); }
.cr-ui .cr-chip-info { color: var(--cr-accent); border-color: rgba(47, 80, 112, .42); background: var(--cr-accent-soft); }

/* Chip bấm được (đổi trạng thái) */
.cr-ui .cr-chip-btn { cursor: pointer; border-style: solid; }
.cr-ui .cr-chip-btn:hover { filter: brightness(.96); }

/* Chip hạng mục nhóm tuổi */
.cr-ui .cr-chip-boys   { color: #1c5fa8; border-color: rgba(28, 95, 168, .42);  background: rgba(28, 95, 168, .11); }
.cr-ui .cr-chip-girls  { color: #b02a5b; border-color: rgba(176, 42, 91, .42);  background: rgba(176, 42, 91, .11); }
.cr-ui .cr-chip-open   { color: #1f7a46; border-color: rgba(31, 122, 70, .42);  background: rgba(31, 122, 70, .11); }
.cr-ui .cr-chip-senior { color: #9a5a00; border-color: rgba(154, 90, 0, .42);   background: rgba(154, 90, 0, .11); }

/* --------------------------------------------------------- TRẠNG THÁI RỖNG */

.cr-ui .cr-empty {
    padding: 30px 16px;
    text-align: center;
    color: var(--cr-ink-3);
    font-size: 13.5px;
}
.cr-ui .cr-empty .cr-empty-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--cr-ink-2);
    margin-bottom: 4px;
}

/* Nút trên thanh tiêu đề phải có khe hở để phân biệt được với nhau. Lớp gap-* của
   Bootstrap không ăn ở đây, nên khoảng cách đặt bằng margin giữa hai nút kề nhau. */
.cr-ui .cr-card-head .crb + .crb,
.cr-ui .cr-card-head a + a,
.cr-ui .cr-card-head button + button,
.cr-ui .cr-card-head a + button,
.cr-ui .cr-card-head button + a { margin-left: 8px; }

/* Ngoài thanh tiêu đề vẫn còn những hàng nút dùng lớp gap-* không ăn (VD "Huỷ lọc" /
   "Xoá cache"), nên khe hở đặt cho mọi cặp nút kề nhau, rồi trừ ra các khối đã có gap
   riêng để không cộng dồn. */
.cr-ui .crb + .crb { margin-left: 8px; }
/* Vài màn hình còn dùng nút Bootstrap thuần (view=clubs) - cũng cần khe hở như vậy. */
.cr-ui .btn + .btn { margin-left: 8px; }
.cr-ui table .btn + .btn,
.cr-ui .modal-footer > .btn + .btn { margin-left: 0; }
/* Chỉ trừ con TRỰC TIẾP của các khối đã có gap - "Huỷ lọc"/"Xoá cache" nằm sâu trong
   .cr-toolbar nhưng ở một hộp con không có gap, nên vẫn phải giữ khe hở. */
.cr-ui table .crb + .crb,
.cr-ui .modal-footer > .crb + .crb,
.cr-ui .cr-navbtns > .crb + .crb,
.cr-ui .cr-toolbar > .crb + .crb,
.cr-ui .cr-choices > .crb + .crb,
.cr-ui .as-grid > .crb + .crb { margin-left: 0; }

/* Nút đứng ngay trước cụm điều hướng cũng cần khe hở (cụm đó là <span>, nên quy tắc
   "nút kề nút" ở trên không với tới). */
.cr-ui .cr-card-head a:has(+ .cr-navbtns),
.cr-ui .cr-card-head button:has(+ .cr-navbtns) { margin-right: 8px; }

/* Cặp nút điều hướng bên phải đã có gap riêng, không cộng thêm. */
.cr-ui .cr-card-head .cr-navbtns a + a,
.cr-ui .cr-card-head .cr-navbtns .crb + .crb,
.cr-ui .cr-card-head .cr-navbtns a + button,
.cr-ui .cr-card-head .cr-navbtns button + a { margin-left: 0; }

/* ---------------------------------------------------------------- POPUP --- */
/* Giữ nguyên cấu trúc modal Bootstrap sẵn có, chỉ chỉnh kích thước cho khớp
   khuôn đã chốt: mọi ô nhập và nút cao 30px. */

.cr-modal .modal-content { border: 0; border-radius: var(--cr-r-card); overflow: hidden; }
.cr-modal .modal-header {
    background: #2f5070;
    padding: 9px 14px;
    border-bottom: 0;
}
.cr-modal .modal-title { color: #fff; font-size: 14.5px; font-weight: 600; }
.cr-modal .modal-body { padding: 14px; }
.cr-modal .modal-footer { padding: 10px 14px; gap: 8px; border-top: 1px solid #dfe4ea; }
.cr-modal .form-label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #4e5c6b;
}
.cr-modal .mb-3 { margin-bottom: 10px !important; }
.cr-modal .form-control,
.cr-modal .form-select {
    width: 100%;
    max-width: 100%;
    height: 30px;
    min-height: 30px;
    padding: 0 10px;
    font-size: 13px;
    line-height: 1.2;
    border: 1px solid #c6ced7;
    border-radius: 6px;
    box-sizing: border-box;
}
.cr-modal .form-control:focus,
.cr-modal .form-select:focus {
    border-color: #2f5070;
    box-shadow: 0 0 0 3px #e9eff6;
    outline: 0;
}
.cr-modal .modal-dialog { max-width: 440px; }

/* A popup that has to hold a row of choices needs more room than a form does. */
.cr-modal.cr-modal-wide .modal-dialog { max-width: 760px; }

/* The choices wrap by themselves instead of being cut off at the edge of the dialog. */
.cr-modal .cr-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 8px;
    width: 100%;
}

/* Text inside a popup follows the same scale as the rest of the screen. */
.cr-modal .modal-body p { font-size: 13px; line-height: 1.5; margin: 0 0 8px; }
.cr-modal .modal-body p:last-child { margin-bottom: 0; }
.cr-modal .alert {
    padding: 8px 10px;
    margin-bottom: 10px;
    font-size: 13px;
    border-radius: 6px;
}
/* Bootstrap để .form-check{padding-left:1.5rem} và .form-check-input{float:left;margin-left:-1.5rem}
   -> phải gỡ cả hai, không thì nút tròn đè lên chữ và nuốt mất nhãn. */
.cr-modal .form-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 18px;
    padding-left: 0;
    min-height: 0;
}
.cr-modal .form-check-input[type="radio"],
.cr-modal .form-check-input[type="checkbox"] {
    position: static;
    float: none;
    width: 15px;
    height: 15px;
    margin: 0;
    flex: 0 0 auto;
    cursor: pointer;
}
.cr-modal .form-check-label { font-size: 13px; cursor: pointer; margin: 0; }

/* ------------------------------------------------------- CHÚ THÍCH NÚT -- */
/* Tooltip sẵn có của trình duyệt (thuộc tính title) đợi gần một giây mới hiện
   và chữ rất nhạt. Cái này hiện ngay, đọc được, dùng cho nút bất kỳ:
   thêm class .cr-tip rồi đặt lời chú vào data-tip (ĐỮNG đặt cả title,
   nếu không sẽ hiện hai hộp chồng nhau). Thêm .cr-tip-end cho nút nằm
   sát mép phải để hộp chú neo theo mép thay vì tràn ra ngoài màn hình. */

.cr-ui .cr-tip { position: relative; }

.cr-ui .cr-tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 9px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    width: max-content;
    max-width: 290px;
    padding: 7px 10px;
    border-radius: 6px;
    background: #2b3440;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.45;
    text-align: left;
    white-space: normal;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
    opacity: 0;
    visibility: hidden;
    transition: opacity .12s ease;
    pointer-events: none;
}

.cr-ui .cr-tip::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 61;
    border: 6px solid transparent;
    border-top-color: #2b3440;
    opacity: 0;
    visibility: hidden;
    transition: opacity .12s ease;
    pointer-events: none;
}

.cr-ui .cr-tip-end::after { left: auto; right: 0; transform: none; }
.cr-ui .cr-tip-end::before { left: auto; right: 14px; transform: none; }

.cr-ui .cr-tip:hover::after,
.cr-ui .cr-tip:hover::before,
.cr-ui .cr-tip:focus-visible::after,
.cr-ui .cr-tip:focus-visible::before { opacity: 1; visibility: visible; }

/* ------------------------------------------------------------ ĐIỆN THOẠI -- */

@media (max-width: 640px) {
    .cr-ui .cr-card-body { padding: 10px; }
    .cr-ui .cr-toolbar { padding: 8px; }
    .cr-ui table.crt th { font-size: 10px; }
    .cr-ui .cr-tip::after, .cr-ui .cr-tip::before { display: none; }
    .cr-ui .cr-scroll { max-height: none; }
}
