/* ==========================================================================
   Nexus UI — App shell (sidebar, topbar, content) + component dùng chung
   cho khu vực quản trị và khu vực khách hàng.
   ========================================================================== */

/* ------------------------------- APP SHELL ------------------------------- */
.app {
    display: flex;
    min-height: 100vh;
    background:
        radial-gradient(900px 520px at 8% -8%, var(--bg-grad-1), transparent 68%),
        radial-gradient(760px 420px at 92% 0%, var(--bg-grad-2), transparent 62%),
        var(--bg);
    background-attachment: fixed;
}

.sidebar {
    position: sticky;
    top: 0;
    width: var(--sidebar-w);
    height: 100vh;
    flex: none;
    padding: 20px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    border-right: 1px solid var(--border);
    background: var(--surface-solid);
    background-image: linear-gradient(180deg, var(--surface) 0%, transparent 42%);
    backdrop-filter: blur(18px);
    z-index: 40;
    transition: transform var(--ease), width var(--ease);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 6px 0;
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(140deg, var(--primary), #a78bfa 55%, var(--primary-2));
    box-shadow: 0 10px 24px -12px var(--primary);
}

.brand-logo .ico {
    width: 21px;
    height: 21px;
    stroke-width: 2;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.brand-text strong {
    font-size: 16px;
    letter-spacing: -0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-text span {
    font-size: 11px;
    color: var(--text-mute);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.brand-close {
    display: none;
    margin-left: auto;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    flex: 1;
    margin: 0 -6px;
    padding: 0 6px;
}

.nav-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-mute);
    font-weight: 600;
    margin: 16px 10px 6px;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13.8px;
    font-weight: 500;
    color: var(--text-dim);
    transition: background var(--ease), color var(--ease), transform var(--ease);
}

.nav-item .ico {
    width: 18px;
    height: 18px;
}

.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.nav-item.active {
    color: var(--text);
    background: linear-gradient(90deg, var(--primary-soft), transparent 92%);
    font-weight: 600;
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: -16px;
    top: 50%;
    translate: 0 -50%;
    width: 3px;
    height: 22px;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(var(--primary), var(--primary-2));
    box-shadow: 0 0 14px var(--primary);
}

.nav-item.active .ico {
    color: var(--primary);
}

.nav-pill,
.nav-count {
    margin-left: auto;
    font-size: 10.5px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    letter-spacing: 0.02em;
}

.nav-pill {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-count {
    background: var(--danger-soft);
    color: var(--danger);
}

.upgrade {
    position: relative;
    overflow: hidden;
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background:
        radial-gradient(120% 90% at 100% 0%, rgba(124, 108, 255, 0.28), transparent 62%),
        var(--surface-2);
}

.upgrade-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(140deg, var(--primary), var(--primary-2));
    margin-bottom: 10px;
}

.upgrade-icon .ico {
    width: 17px;
    height: 17px;
}

.upgrade-title {
    font-size: 13.5px;
    font-weight: 700;
}

.upgrade-desc {
    font-size: 11.8px;
    color: var(--text-dim);
    margin: 5px 0 12px;
    line-height: 1.5;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
    flex: 1;
}

.sidebar-user-info strong {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-info span {
    font-size: 11px;
    color: var(--text-mute);
}

.avatar {
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #fff;
    background: linear-gradient(140deg, #f472b6, #7c6cff 60%, #22d3ee);
    box-shadow: 0 8px 20px -12px var(--primary);
}

.avatar-sm {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    font-size: 11.5px;
}

.avatar-lg {
    width: 64px;
    height: 64px;
    font-size: 20px;
    border-radius: 20px;
}

/* --------------------------------- MAIN --------------------------------- */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 26px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    backdrop-filter: blur(16px) saturate(140%);
}

.search {
    display: flex;
    align-items: center;
    gap: 9px;
    width: min(420px, 100%);
    min-width: 0;
    /* min-width:0 → ô tìm kiếm co lại được trên mobile
     * (mặc định flex item có min-width:auto → không co dưới nội dung) */
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-mute);
    transition: border-color var(--ease), box-shadow var(--ease);
}

.search:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: none;
    font-size: 13.2px;
    color: var(--text);
}

.search input::placeholder {
    color: var(--text-mute);
}

.search kbd {
    font-family: var(--font);
    font-size: 10.5px;
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface-3);
    color: var(--text-mute);
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: none;
}

.live {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 11.8px;
    font-weight: 600;
    color: var(--success);
    padding: 6px 11px;
    border-radius: var(--radius-full);
    background: var(--success-soft);
    border: 1px solid rgba(52, 211, 153, 0.22);
}

.live .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
    }

    50% {
        box-shadow: 0 0 0 7px rgba(52, 211, 153, 0);
    }
}

.icon-btn {
    position: relative;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    transition: background var(--ease), color var(--ease), border-color var(--ease), transform var(--ease);
}

.icon-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-strong);
}

.icon-btn:active {
    transform: scale(0.96);
}

.noti-dot {
    position: absolute;
    top: 9px;
    right: 10px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--surface-solid);
}

.dropdown {
    position: relative;
}

.dropdown-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 12px);
    width: 340px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-solid);
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(0.985);
    transition: all var(--ease);
    overflow: hidden;
}

.dropdown.open .dropdown-panel {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.dropdown-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.dropdown-head strong {
    font-size: 13.5px;
}

.noti-list li {
    display: flex;
    gap: 11px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background var(--ease);
}

.noti-list li:hover {
    background: var(--surface-hover);
}

.noti-list p {
    font-size: 12.8px;
    line-height: 1.45;
}

.noti-list .u-mute {
    font-size: 11px;
}

.noti-ico {
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: 9px;
    display: grid;
    place-items: center;
}

.noti-ico.ok {
    background: var(--success-soft);
    color: var(--success);
}

.noti-ico.warn {
    background: var(--warning-soft);
    color: var(--warning);
}

.noti-ico.info {
    background: var(--primary-soft);
    color: var(--primary);
}

.dropdown-foot {
    width: 100%;
    padding: 12px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--primary);
    background: var(--surface-2);
    text-align: left;
}

.dropdown-foot:hover {
    background: var(--surface-3);
}

/* Menu tài khoản trên topbar */
.user-menu {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 10px 6px 6px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: background var(--ease), border-color var(--ease);
}

.user-menu:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
}

.user-menu-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    text-align: left;
    max-width: 170px;
}

.user-menu-text strong {
    font-size: 12.6px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu-text span {
    font-size: 10.8px;
    color: var(--text-mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 12px);
    min-width: 230px;
    padding: 7px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-solid);
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(0.985);
    transition: all var(--ease);
    z-index: 60;
}

.dropdown.open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.dropdown-menu a,
.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 11px;
    border-radius: 9px;
    font-size: 13px;
    color: var(--text-dim);
    text-align: left;
    transition: background var(--ease), color var(--ease);
}

.dropdown-menu a:hover,
.dropdown-menu button:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.dropdown-menu .ico {
    width: 16px;
    height: 16px;
}

.dropdown-sep {
    height: 1px;
    margin: 6px 4px;
    background: var(--border);
}

.balance-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(124, 108, 255, 0.28);
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12.5px;
    font-weight: 700;
    font-family: var(--mono);
}

/* --------------------------------- CONTENT ------------------------------ */
.content {
    padding: 26px;
    max-width: 1560px;
    width: 100%;
    margin: 0 auto;
}

.content>section+section,
.content>.grid+.grid,
.content>.stats+.grid {
    margin-top: 20px;
}

/* ------------------------------- PAGE HEAD ------------------------------ */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.crumbs {
    font-size: 11.8px;
    color: var(--text-mute);
    margin-bottom: 6px;
}

.crumbs span {
    opacity: 0.5;
    margin: 0 4px;
}

.page-head h1 {
    font-size: clamp(22px, 2.4vw, 30px);
    letter-spacing: -0.035em;
}

.page-sub {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 6px;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.seg {
    display: inline-flex;
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
}

.seg-btn {
    padding: 7px 13px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 9px;
    color: var(--text-dim);
    transition: all var(--ease);
}

.seg-btn:hover {
    color: var(--text);
}

.seg-btn.active {
    background: var(--surface-3);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* --------------------------------- GRID --------------------------------- */
.grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.span-3 {
    grid-column: span 3;
}

.span-4 {
    grid-column: span 4;
}

.span-5 {
    grid-column: span 5;
}

.span-6 {
    grid-column: span 6;
}

.span-7 {
    grid-column: span 7;
}

.span-8 {
    grid-column: span 8;
}

.span-12 {
    grid-column: span 12;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 0;
}

.stack .card {
    flex: 1;
}

.g-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.g-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.g-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

/* ---------------------------------- KPI --------------------------------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.kpi {
    padding: 18px 18px 14px;
    overflow: hidden;
    position: relative;
    transition: transform var(--ease), border-color var(--ease), box-shadow var(--ease);
}

.kpi::after {
    content: "";
    position: absolute;
    inset: auto -30% -60% auto;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--primary-soft), transparent 70%);
    pointer-events: none;
}

.kpi:hover {
    transform: translateY(-3px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
}

.kpi-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.kpi-ico {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
}

.kpi-ico .ico {
    width: 19px;
    height: 19px;
}

.v-primary {
    color: var(--primary);
    background: var(--primary-soft);
}

.v-cyan {
    color: var(--primary-2);
    background: rgba(34, 211, 238, 0.13);
}

.v-pink {
    color: var(--accent);
    background: rgba(244, 114, 182, 0.14);
}

.v-amber {
    color: var(--warning);
    background: var(--warning-soft);
}

.v-success {
    color: var(--success);
    background: var(--success-soft);
}

.v-danger {
    color: var(--danger);
    background: var(--danger-soft);
}

.kpi-label {
    font-size: 12.2px;
    color: var(--text-dim);
    font-weight: 500;
}

.kpi-value {
    font-size: clamp(20px, 2vw, 27px);
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-top: 4px;
}

.kpi-unit {
    font-size: 0.6em;
    color: var(--text-dim);
    margin-left: 3px;
    font-weight: 600;
}

.spark {
    height: 46px;
    margin: 10px -6px 6px;
}

.kpi-foot {
    font-size: 11.6px;
    color: var(--text-mute);
}

.kpi-foot b {
    color: var(--text-dim);
    font-weight: 600;
}

/* ------------------------------- CHART CARD ----------------------------- */
.chart-card {
    padding: 18px;
}

.chart-card .card-head {
    padding: 0;
}

.chart-card .card-title {
    font-size: 14.5px;
    letter-spacing: -0.02em;
}

.chart-card .card-sub {
    font-size: 11.8px;
    color: var(--text-mute);
    margin-top: 3px;
}

.legend-inline {
    display: flex;
    gap: 14px;
    font-size: 11.8px;
    color: var(--text-dim);
    flex-wrap: wrap;
}

.legend-inline span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.lg {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    display: inline-block;
}

.lg-a {
    background: linear-gradient(140deg, #7c6cff, #a78bfa);
}

.lg-b {
    background: linear-gradient(140deg, #f472b6, #fb7185);
}

.lg-c {
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
}

.chart-body {
    position: relative;
    height: 268px;
}

.chart-body.tall {
    height: 300px;
}

.chart-body.donut {
    height: 214px;
    display: grid;
    place-items: center;
}

.donut-center {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
    pointer-events: none;
}

.donut-center strong {
    font-size: 22px;
    letter-spacing: -0.03em;
}

.donut-center span {
    font-size: 11px;
    color: var(--text-mute);
}

.legend-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 16px;
}

.legend-list li {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 12.4px;
    color: var(--text-dim);
}

.legend-list i {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    flex: none;
}

.legend-list b {
    margin-left: auto;
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
}

.card-foot-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px dashed var(--border);
}

.card-foot-stats div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card-foot-stats span {
    font-size: 11px;
}

.card-foot-stats strong {
    font-size: 13.5px;
    letter-spacing: -0.02em;
}

.link-more {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12.2px;
    font-weight: 600;
    color: var(--primary);
    transition: gap var(--ease);
}

.link-more:hover {
    gap: 8px;
}

/* --------------------------------- TABLE -------------------------------- */
.table-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 16px 0 12px;
}

.chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    transition: all var(--ease);
}

.chip span {
    font-size: 10.5px;
    padding: 1px 5px;
    border-radius: 99px;
    background: var(--surface-3);
    color: var(--text-mute);
    font-variant-numeric: tabular-nums;
}

.chip:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.chip.active span {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.mini-search {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 11px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-mute);
}

.mini-search input {
    border: 0;
    outline: 0;
    background: none;
    font-size: 12.5px;
    width: 190px;
    color: var(--text);
}

.mini-search:focus-within {
    border-color: var(--primary);
}

/* Bảng trên mobile: cuộn ngang BÊN TRONG .table-wrap, không làm vỡ trang.
 * -webkit-overflow-scrolling: touch → cuộn mượt trên iOS
 * overscroll-behavior-x: contain → không kéo cuộn trang khi cuộn bảng
 */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    margin: 0 -18px;
    padding: 0 18px;
}

.card .table-wrap {
    margin: 0;
    padding: 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.9px;
    min-width: 640px;
}

/* Bảng nhãn / giá trị (2 cột) — KHÔNG cần min-width 640px.
 * Dùng trong card 2 cột (span-6) để tránh tràn ngang ở laptop/mobile. */
.table-kv {
    min-width: 0;
}

.table-kv td {
    padding: 11px 0;
}

.table-kv td:first-child {
    padding-right: 14px;
    white-space: nowrap;
}

.table-kv td:last-child {
    text-align: right;
    word-break: break-word;
}

.table th {
    text-align: left;
    font-size: 10.8px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-mute);
    font-weight: 600;
    padding: 0 12px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr {
    transition: background var(--ease);
}

.table tbody tr:hover {
    background: var(--surface-hover);
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.ta-r {
    text-align: right;
}

.cell-user {
    display: flex;
    align-items: center;
    gap: 9px;
}

.cell-user .avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 10.5px;
}

.cell-user strong {
    font-weight: 600;
    font-size: 12.9px;
    display: block;
}

.cell-user span {
    font-size: 11px;
    color: var(--text-mute);
}

.order-id {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-dim);
}

.amount {
    font-family: var(--mono);
    font-weight: 600;
    font-size: 12.6px;
}

.row-act {
    text-align: right;
}

.col-check {
    width: 34px;
}

.cell-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.empty {
    padding: 26px;
    text-align: center;
    color: var(--text-mute);
    font-size: 13px;
}

/* ------------------------- BẢNG GỌN (admin/users) -------------------------
 * Bảng người dùng có nhiều cột + nhiều nút → gom số liệu phụ vào 1 ô,
 * dùng icon nhỏ cho thao tác để bảng gọn và không tràn ngang.
 */
.table-users td {
    padding: 8px 10px;
}

.table-users th {
    padding: 0 10px 8px;
}

.table-users .num {
    white-space: nowrap;
    line-height: 1.35;
    vertical-align: middle;
}

.table-users .num strong {
    font-family: var(--mono);
    font-weight: 700;
    font-size: 12.6px;
}

/* Số liệu phụ (đơn / token) nằm CÙNG DÒNG với số chính — không xuống dòng. */
.table-users .num small {
    display: inline;
    margin-left: 4px;
    font-size: 10.5px;
    font-weight: 400;
    color: var(--text-mute);
}

.table-users .sm {
    font-size: 11.4px;
}

.table-users .cell-user .avatar {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    font-size: 10px;
}

.table-users .cell-user strong {
    font-size: 12.4px;
}

/* Email dài → cắt bằng "…" để cột Người dùng không nở rộng
 * và không đẩy các cột khác ra ngoài bảng. */
.table-users .cell-user > span:last-child {
    min-width: 0;
}

.table-users .cell-user strong a {
    display: block;
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-users .cell-user span span {
    display: block;
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-users .cell-user span {
    font-size: 10.6px;
}

/* Nhóm nút hành động cuối dòng */
.u-rowacts {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    flex-wrap: nowrap;
}

/* Nút icon nhỏ (24–28px) cho ô hành động */
.icon-btn-sm {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    flex: none;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-dim);
    cursor: pointer;
    transition: background var(--ease), color var(--ease), border-color var(--ease);
}

.icon-btn-sm:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-strong);
}

.icon-btn-sm.v-green {
    color: var(--success);
}

.icon-btn-sm.v-green:hover {
    background: var(--success-soft);
    border-color: rgba(52, 211, 153, 0.35);
}

.icon-btn-sm.v-red {
    color: var(--danger);
}

.icon-btn-sm.v-red:hover {
    background: var(--danger-soft);
    border-color: rgba(251, 113, 133, 0.35);
}

/* Select nhỏ dùng trong ô của bảng */
.select-xs {
    width: auto;
    min-width: 78px;
    padding: 4px 26px 4px 8px;
    font-size: 11.6px;
    border-radius: 8px;
    background-position: calc(100% - 14px) 51%, calc(100% - 9px) 51%;
}

/* Card-head gọn + filterbar phẳng (không viền/đổ bóng) */
.card-head-tight {
    align-items: center;
    padding: 14px 16px 0;
    gap: 12px;
}

.filterbar-flat {
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
    backdrop-filter: none;
    gap: 8px;
    /* co giãn được trong .card-head (flex-wrap) → không tràn ngang */
    flex: 1 1 220px;
    min-width: 0;
    max-width: 420px;
}

.filterbar-flat .input-search {
    flex: 1 1 140px;
    min-width: 0;
}

.input-search-sm {
    padding: 6px 10px;
}

.input-search-sm input {
    font-size: 12.6px;
}

/* --------------------- BẢNG GỌN (admin/topups) ---------------------
 * Bảng đơn nạp tiền: nhiều cột + nhiều nút → gom số liệu về 1 ô,
 * thao tác dùng icon nhỏ để bảng gọn và không tràn ngang.
 */
.table-topups td {
    padding: 7px 9px;
}

.table-topups th {
    padding: 0 9px 8px;
}

.table-topups .num {
    white-space: nowrap;
    line-height: 1.35;
    vertical-align: middle;
    font-size: 12.4px;
}

.table-topups .num strong {
    font-family: var(--mono);
    font-weight: 700;
    font-size: 12.6px;
}

.table-topups .sm {
    font-size: 11.2px;
}

.table-topups .cell-user .avatar {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    font-size: 10px;
}

.table-topups .cell-user strong {
    font-size: 12.4px;
}

/* Email dài → cắt bằng "…" để cột Người dùng không nở rộng. */
.table-topups .cell-user > span:last-child {
    min-width: 0;
}

.table-topups .cell-user strong a {
    display: block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-topups .cell-user span span {
    display: block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-topups .cell-user span {
    font-size: 10.6px;
}

/* Mã đơn + tham chiếu: mã đơn trên, tham chiếu nhỏ bên dưới (cùng dòng) */
.table-topups .ref-line {
    display: block;
    margin-top: 1px;
    font-size: 10.4px;
    color: var(--text-mute);
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --------------------------- MÃ QR THANH TOÁN --------------------------- */
/* base.css đặt `img { display: block }` → ảnh không được canh giữa bởi
   `text-align:center` của .card-body (block-level, co theo mép trái).
   .qr-box dùng flexbox để QR luôn nằm chính giữa card. */
.qr-box {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    width: 100%;
}

.qr-box img {
    display: block;
    margin: 0 auto;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.pager-btns {
    display: flex;
    gap: 6px;
}

.btn-xs.active {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-soft);
}

.pagination {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 9px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-dim);
    transition: all var(--ease);
}

.page-link:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.page-link.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.page-link.disabled,
.page-link.disabled:hover {
    color: var(--text-dim);
    opacity: .45;
    cursor: default;
    border-color: var(--border);
    background: var(--surface-2);
}

/* -------------------------------- TIMELINE ------------------------------ */
.timeline {
    display: flex;
    flex-direction: column;
}

.tl-item {
    position: relative;
    padding: 0 0 16px 22px;
    border-left: 1px solid var(--border);
}

.tl-item:last-child {
    padding-bottom: 0;
    border-left-color: transparent;
}

.tl-dot {
    position: absolute;
    left: -5px;
    top: 5px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 3px var(--surface-solid);
}

.tl-item p {
    font-size: 12.7px;
    line-height: 1.5;
    color: var(--text-dim);
}

.tl-item b {
    color: var(--text);
    font-weight: 600;
}

.tl-time {
    display: block;
    font-size: 11px;
    color: var(--text-mute);
    margin-top: 3px;
}

/* --------------------------------- BARS --------------------------------- */
.goals .goal {
    margin-bottom: 13px;
}

.goals .goal:last-child {
    margin-bottom: 0;
}

.goal>div:first-child {
    font-size: 12.4px;
    margin-bottom: 6px;
}

.bar {
    height: 7px;
    border-radius: 99px;
    background: var(--surface-3);
    overflow: hidden;
}

.bar i {
    display: block;
    height: 100%;
    width: var(--w, 0%);
    border-radius: inherit;
    background: currentColor;
    transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}

.bar i.v-primary {
    background: linear-gradient(90deg, var(--primary), #a78bfa);
}

.bar i.v-cyan {
    background: linear-gradient(90deg, var(--primary-2), #38bdf8);
}

.bar i.v-pink {
    background: linear-gradient(90deg, var(--accent), #fb7185);
}

.bar i.v-amber {
    background: linear-gradient(90deg, var(--warning), #fcd34d);
}

.bar i.v-success {
    background: linear-gradient(90deg, var(--success), #6ee7b7);
}

.progress-mini {
    width: 92px;
    height: 6px;
    border-radius: 99px;
    background: var(--surface-3);
    overflow: hidden;
}

.progress-mini i {
    display: block;
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
}

/* -------------------------------- HEALTH -------------------------------- */
.health {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.health-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.health-item>span {
    font-size: 11.6px;
    color: var(--text-mute);
}

.health-item strong {
    font-size: 14px;
    letter-spacing: -0.02em;
}

/* --------------------------------- FOOTER ------------------------------- */
.foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px 2px 4px;
    font-size: 11.6px;
    color: var(--text-mute);
}

/* --------------------------- THẺ SỐ LIỆU / STATS ------------------------ */
.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.stats.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    transition: transform var(--ease), border-color var(--ease), box-shadow var(--ease);
}

.stat:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-glow);
}

.stat-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.stat-ico {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(140deg, var(--primary), var(--primary-2));
    box-shadow: 0 10px 22px -14px var(--primary);
}

.stat-ico.v-cyan {
    background: linear-gradient(140deg, #0891b2, #22d3ee);
    box-shadow: 0 10px 22px -14px #22d3ee;
}

.stat-ico.v-pink {
    background: linear-gradient(140deg, #db2777, #f9a8d4);
    box-shadow: 0 10px 22px -14px #f472b6;
}

.stat-ico.v-amber {
    background: linear-gradient(140deg, #d97706, #fbbf24);
    box-shadow: 0 10px 22px -14px #fbbf24;
}

.stat-ico.v-green {
    background: linear-gradient(140deg, #059669, #34d399);
    box-shadow: 0 10px 22px -14px #34d399;
}

.stat-label {
    font-size: 12.5px;
    color: var(--text-mute);
    font-weight: 500;
}

.stat-value {
    font-size: 25px;
    font-weight: 750;
    letter-spacing: -0.03em;
    line-height: 1.1;
    /* số/ngày dạng "09/11/2026" không được cắt khi card hẹp */
    overflow-wrap: anywhere;
    word-break: break-word;
}

.stat-value small {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dim);
    margin-left: 2px;
}

.stat-foot {
    font-size: 12px;
    color: var(--text-mute);
}

.stat-foot b {
    color: var(--text-dim);
    font-weight: 600;
}

/* -------------------------------- BỘ LỌC -------------------------------- */
.filterbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
}

.filterbar .grow {
    flex: 1 1 240px;
    min-width: 200px;
}

.filterbar .spacer {
    flex: 1;
}

.input-search {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-mute);
    transition: border-color var(--ease), box-shadow var(--ease);
}

.input-search:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.input-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: none;
    outline: none;
    font-size: 13.5px;
    color: var(--text);
    /* cao bằng ô chứa → dễ bấm trên mobile */
    min-height: 22px;
}

@media (max-width: 820px) {
    .input-search {
        min-height: 44px;
        padding: 5px 12px;
        align-items: stretch;
    }

    .input-search svg {
        align-self: center;
        flex: none;
    }

    .input-search input {
        font-size: 16px;
        /* 16px tránh iOS tự zoom khi focus */
        align-self: stretch;
        height: auto;
        min-height: 34px;
    }
}

/* --------------------------------- TABS --------------------------------- */
.tabs {
    display: flex;
    gap: 4px;
    padding: 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

.tab {
    padding: 9px 16px;
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-dim);
    white-space: nowrap;
    transition: background var(--ease), color var(--ease);
}

.tab:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.tab.active {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #8f7bff 70%, var(--primary-2));
    box-shadow: 0 10px 22px -16px var(--primary);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fade-up 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

/* -------------------------------- SWITCH -------------------------------- */
.switch-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 0;
    border-bottom: 1px dashed var(--border);
}

.switch-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.switch-row:first-child {
    padding-top: 0;
}

.switch-row strong {
    display: block;
    font-size: 13.5px;
    font-weight: 600;
}

.switch-row p {
    margin-top: 3px;
    font-size: 12.5px;
    color: var(--text-mute);
    max-width: 46ch;
}

.switch {
    position: relative;
    width: 44px;
    height: 25px;
    flex: none;
    border-radius: 99px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    transition: background var(--ease), border-color var(--ease);
}

.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: var(--text-mute);
    transition: transform var(--ease), background var(--ease);
}

.switch.on {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border-color: transparent;
}

.switch.on::after {
    transform: translateX(19px);
    background: #fff;
}

/* ------------------------------- FORM GRID ------------------------------ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 6px;
}

/* ------------------------------ PLAN CARD ------------------------------- */
.plan-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.plan-card {
    position: relative;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: hidden;
    transition: transform var(--ease), border-color var(--ease), box-shadow var(--ease);
}

.plan-card:hover {
    transform: translateY(-4px);
    border-color: var(--border-strong);
}

.plan-card.featured {
    border-color: rgba(124, 108, 255, 0.55);
    background: linear-gradient(180deg, var(--primary-soft), transparent 55%), var(--surface);
    box-shadow: var(--shadow-glow);
}

.plan-badge {
    position: absolute;
    top: 16px;
    right: 16px;
}

.plan-name {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-mute);
}

.plan-feats {
    display: flex;
    flex-direction: column;
    gap: 9px;
    font-size: 13px;
    color: var(--text-dim);
}

.plan-feats li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.plan-feats .ico {
    color: var(--success);
    margin-top: 2px;
    width: 16px;
    height: 16px;
    flex: none;
}

.plan-card .btn {
    margin-top: auto;
}

/* --------------------------------- CELLS -------------------------------- */
.cust {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
    font-size: 13px;
}

.cust strong {
    font-weight: 600;
    letter-spacing: -0.01em;
}

.cust span {
    font-size: 11.5px;
    color: var(--text-mute);
}

.lg-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 13px;
}

.lg-row:last-child {
    border-bottom: 0;
}

.lg-name {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text-dim);
}

.lg-dot {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    flex: none;
}

.lg-row b {
    font-family: var(--mono);
    font-weight: 600;
    font-size: 12.8px;
}

/* -------------------------------- KEY / CODE ----------------------------- */
.kv {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 13px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 13.2px;
}

.kv:last-child {
    border-bottom: 0;
}

.kv .u-mute {
    font-size: 12.5px;
}

.code-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--text-dim);
    overflow: hidden;
}

.code-box code {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* -------------------------------- ACCORDION ----------------------------- */
.accordion {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.acc-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
    transition: border-color var(--ease), background var(--ease);
}

.acc-item[open] {
    border-color: rgba(124, 108, 255, 0.45);
    background: var(--surface-2);
}

.acc-item summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 15px 18px;
    font-size: 13.8px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.acc-item summary::-webkit-details-marker {
    display: none;
}

.acc-item summary::after {
    content: "+";
    font-size: 19px;
    font-weight: 400;
    color: var(--text-mute);
    transition: transform var(--ease), color var(--ease);
    line-height: 1;
}

.acc-item[open] summary::after {
    transform: rotate(45deg);
    color: var(--primary);
}

.acc-body {
    padding: 0 18px 16px;
    font-size: 13.2px;
    color: var(--text-dim);
    line-height: 1.65;
}

/* --------------------------------- MODAL -------------------------------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(4, 7, 15, 0.62);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--ease), visibility var(--ease);
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    width: 100%;
    max-width: 540px;
    max-height: 88vh;
    overflow-y: auto;
    background: var(--surface-solid);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transform: translateY(16px) scale(0.98);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.show .modal-card {
    transform: none;
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 22px 14px;
}

.modal-head h2 {
    font-size: 17px;
}

.modal-body {
    padding: 0 22px 20px;
    display: flex;
    flex-direction: column;
    gap: 13px;
}

.modal-body label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-dim);
}

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

/* ------------------------------- SCRIM ---------------------------------- */
.scrim {
    position: fixed;
    inset: 0;
    background: rgba(4, 7, 15, 0.6);
    backdrop-filter: blur(3px);
    z-index: 35;
    opacity: 0;
    visibility: hidden;
    transition: all var(--ease);
}

.scrim.show {
    opacity: 1;
    visibility: visible;
}

/* -------------------------------- TOAST --------------------------------- */
.toast-wrap {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 320;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    min-width: 240px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface-solid);
    box-shadow: var(--shadow);
    font-size: 12.8px;
    font-weight: 500;
    color: var(--text);
    animation: toastIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast .ico {
    color: var(--success);
    flex: none;
}

.toast.err .ico {
    color: var(--danger);
}

.toast.info .ico {
    color: var(--primary);
}

.toast.out {
    animation: toastOut 0.24s forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(24px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(24px);
    }
}

/* ----------------------------- CHART ERROR ------------------------------ */
.chart-error {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 12.6px;
    margin: 0;
}

.only-mobile {
    display: none;
}

/* ------------------------------- RESPONSIVE ----------------------------- */
@media (max-width: 1400px) {
    .span-4 {
        grid-column: span 5;
    }

    .span-8 {
        grid-column: span 7;
    }

    .span-7 {
        grid-column: span 6;
    }

    .span-5 {
        grid-column: span 6;
    }
}

@media (max-width: 1180px) {
    .kpi-grid,
    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .span-3,
    .span-4,
    .span-5,
    .span-6,
    .span-7,
    .span-8 {
        grid-column: span 1;
    }

    .span-8,
    .grid .span-8 {
        grid-column: span 2;
    }

    .stack {
        grid-column: span 1;
    }

    .plan-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .g-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow);
    }

    .sidebar.open {
        transform: none;
    }

    .brand-close {
        display: grid;
    }

    .only-mobile {
        display: grid;
    }
}

@media (max-width: 820px) {
    .content {
        padding: 18px 16px;
    }

    /* Chip chọn mức nạp: vùng chạm lớn hơn cho ngón tay */
    .chip {
        min-height: 38px;
        padding: 8px 14px;
        font-size: 12.6px;
    }

    .topbar {
        padding: 0 16px;
        height: 64px;
        gap: 10px;
    }

    .search {
        width: auto;
        flex: 1 1 auto;
        min-width: 0;
    }

    .search kbd,
    .live {
        display: none;
    }

    /* Ô tìm kiếm chiếm hết chỗ → trên mobile thu gọn còn icon,
     * bấm/focus thì mới bung rộng (giữ nguyên hành vi desktop,
     * tránh làm topbar tràn ngang). */
    .search {
        flex: 0 1 auto;
        width: auto;
        min-width: 0;
        overflow: hidden;
        padding: 9px;
    }

    .search input {
        min-width: 0;
        width: 0;
        opacity: 0;
        transition: width var(--ease), opacity var(--ease);
    }

    .search:focus-within {
        flex: 1 1 auto;
    }

    .search:focus-within input {
        width: 100%;
        opacity: 1;
    }

    /* Nút "Đơn nạp tiền" trùng với mục trong sidebar → ẩn trên mobile */
    .topbar-actions > a.icon-btn[href*="topups"],
    .topbar-actions > a.icon-btn[href*="billing"] {
        display: none;
    }

    .user-menu {
        padding: 5px 8px 5px 5px;
    }

    /* Dropdown menu: rộng tối đa theo màn hình, không tràn */
    .dropdown-menu {
        min-width: min(230px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }

    /* ★ minmax(0, 1fr) — KHÔNG dùng `1fr`!
     *
     * VÌ SAO?
     *   Với `grid-template-columns: 1fr`, item trong grid có
     *   `min-width: auto` → KHÔNG nhỏ hơn nội dung tối thiểu → cột bị
     *   nới rộng vượt quá container → TRÀN NGANG toàn trang.
     *   `minmax(0, 1fr)` ép cột co lại đúng bằng container, nội dung dài
     *   bên trong tự cuộn (đã có overflow-x ở .table-wrap / .code-block).
     */
    .kpi-grid,
    .stats {
        grid-template-columns: minmax(0, 1fr);
    }

    .grid,
    .g-2,
    .g-3,
    .g-4 {
        grid-template-columns: minmax(0, 1fr);
    }

    .grid .span-8,
    .span-8,
    .stack {
        grid-column: span 1;
    }

    .card-foot-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
    }

    .page-actions {
        width: 100%;
    }

    .seg {
        flex: 1;
        justify-content: space-between;
    }

    .health {
        grid-template-columns: minmax(0, 1fr);
    }

    .form-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .plan-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .toast-wrap {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
}

@media (max-width: 520px) {
    .kpi-value {
        font-size: 22px;
    }

    .page-head h1 {
        font-size: 22px;
    }

    .mini-search input {
        width: 120px;
    }

    .user-menu-text {
        display: none;
    }
}

/* ==========================================================================
   TỐI ƯU MOBILE (≤ 520px) — vòng tinh chỉnh cho màn hình nhỏ
   ========================================================================== */
@media (max-width: 520px) {

    /* --- Topbar: giảm chiều cao & khoảng cách, giữ nút bấm đủ lớn --- */
    .topbar {
        height: 58px;
        gap: 10px;
    }

    .topbar-actions {
        gap: 6px;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    /* --- Nội dung: giảm padding ngang --- */
    .content {
        padding: 16px 12px;
    }

    .card,
    .chart-card {
        padding: 14px;
    }

    /* --- Bảng: bỏ min-width cứng để bảng vừa màn hình, cột tự co --- */
    .table-wrap {
        margin: 0 -14px;
        padding: 0 14px;
    }

    .table {
        min-width: 560px;
        font-size: 12.2px;
    }

    /* Bảng nhãn/giá trị vẫn vừa khung ở mobile */
    .table-kv {
        min-width: 0;
    }

    .table-kv td {
        padding: 10px 0;
    }

    /* Ô nhập trong bảng: cao hơn cho dễ bấm trên mobile */
    .table .input,
    .table .select {
        min-height: 34px;
        font-size: 13px;
        padding: 7px 10px;
    }

    .table th,
    .table td {
        padding: 11px 9px;
    }

    /* --- Biểu đồ: thấp hơn cho màn hình nhỏ --- */
    .chart-body {
        height: 220px;
    }

    .chart-body.tall {
        height: 240px;
    }

    .chart-body.donut {
        height: 190px;
    }

    /* --- Số dư: rút gọn để đỡ chiếm chỗ --- */
    .balance-chip {
        padding: 6px 10px;
        font-size: 11.8px;
    }

    /* --- Màn hình rất hẹp (≤ 400px): ẩn số dư trên topbar ---
     * Số dư vẫn xem được trong menu tài khoản / trang Nạp tiền.
     * Ẩn đi để ô tìm kiếm có chỗ bung rộng khi focus. */
    .topbar-actions .balance-chip {
        display: none;
    }

    /* --- Nút: chiều cao tối thiểu 40px cho chạm ngón tay --- */
    .btn {
        min-height: 40px;
    }

    .btn-sm {
        min-height: 36px;
    }

    .btn-xs {
        min-height: 34px;
        min-width: 34px;
        padding: 6px 11px;
    }

    /* --- Link "Xem thêm": vùng chạm thoải mái trên mobile --- */
    .link-more {
        min-height: 34px;
        padding: 4px 0;
        align-items: center;
    }

    /* --- Form: input/select/textarea cao hơn, không tràn --- */
    .input,
    .select,
    .textarea {
        font-size: 16px;
        /* 16px tránh iOS tự zoom khi focus vào input */
    }

    /* --- Filter/segment: cho phép cuộn ngang thay vì vỡ layout --- */
    .seg,
    .filter-row {
        flex-wrap: wrap;
    }

    /* --- Sidebar drawer: rộng tối đa 82% màn hình --- */
    .sidebar {
        width: min(82vw, var(--sidebar-w));
    }

    /* --- Pagination: nút bấm to hơn --- */
    .pagination .btn-xs,
    .pagination button,
    .pagination .page-link {
        min-width: 36px;
        min-height: 36px;
        height: 36px;
    }

    /* --- Lưới: item không được nới rộng vượt container --- */
    .grid > *,
    .g-2 > *,
    .g-3 > *,
    .g-4 > *,
    .kpi-grid > *,
    .stats > *,
    .plan-grid > *,
    .form-grid > *,
    .health > *,
    .span-3,
    .span-4,
    .span-5,
    .span-6,
    .span-7,
    .span-8 {
        min-width: 0;
    }

    /* --- Nội dung dài trong thẻ: ngắt dòng thay vì tràn --- */
    .card-body,
    .card-foot,
    .kpi,
    .u-between,
    .u-row {
        min-width: 0;
    }

    .u-between,
    .u-row {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    /* --- Bảng người dùng (admin/users): icon thao tác to hơn cho chạm tay --- */
    .table-users .icon-btn-sm {
        width: 32px;
        height: 32px;
        border-radius: 9px;
    }

    .table-users .select-xs {
        min-height: 34px;
        padding: 6px 26px 6px 9px;
    }

    /* --- Bảng đơn nạp tiền (admin/topups) --- */
    .table-topups .icon-btn-sm {
        width: 32px;
        height: 32px;
        border-radius: 9px;
    }

    .table-topups .select-xs {
        min-height: 34px;
        padding: 6px 26px 6px 9px;
    }
}
