/* ==========================================================================
   NineInvoiceHub — Design system (Glassmorphism / Premium)
   Single source of truth: design tokens + typography + component styles.
   Font: Be Vietnam Pro (tối ưu hiển thị tiếng Việt nhiều dấu).
   Phong cách: aurora background + glass surfaces (blur, trong suốt, bóng sâu).
   ========================================================================== */

:root {
    /* Brand & semantic colors — OKLCH (gam P3, sống hơn trên màn hiện đại).
       Giá trị hex gốc ghi kèm để đối chiếu/không trôi màu. */
    --primary: oklch(0.541 0.226 277.0);   /* #4f46e5 */
    --primary-hover: oklch(0.470 0.222 277.5); /* #4338ca */
    --primary-soft: #eef2ff;                 /* tint sáng — giữ hex, P3 không thêm gì */
    --accent: oklch(0.715 0.144 215.2);     /* #06b6d4 */
    --success: oklch(0.627 0.176 149.3);    /* #16a34a */
    --danger: oklch(0.637 0.230 22.5);      /* #e11d48 */
    --warning: oklch(0.667 0.163 57.7);     /* #d97706 */
    --info: oklch(0.625 0.118 221.7);       /* #0891b2 */

    /* Soft tints (flat monochrome chips — 2026 style, no gradients) */
    --primary-tint: #eef1ff;
    --accent-tint:  #e0f7fb;
    --success-tint: #e4f7ec;
    --amber-tint:   #fdf2dd;
    --danger-tint:  #fde8ec;

    /* Gradients */
    --grad-primary: linear-gradient(135deg, #6366f1 0%, #4f46e5 50%, #7c3aed 100%);
    --grad-accent: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    --grad-success: linear-gradient(135deg, #34d399 0%, #059669 100%);
    --grad-danger: linear-gradient(135deg, #fb7185 0%, #e11d48 100%);
    --grad-amber: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);

    /* Neutrals */
    --bg: #f7f8fb;
    --surface: #ffffff;
    --border: #e8eaf1;
    --border-strong: #d7dae5;
    --text: #1e2230;
    --text-muted: #6b7185;
    --text-faint: #9aa0b4;

    /* Glass tokens */
    --glass-bg: rgba(255, 255, 255, 0.62);
    --glass-bg-strong: rgba(255, 255, 255, 0.78);
    --glass-border: rgba(255, 255, 255, 0.7);
    --glass-blur: saturate(180%) blur(18px);

    /* Sidebar (dark glass) */
    --sidebar-fg: #c7cddf;

    /* Typography scale */
    --font-sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --fs-xs: 0.75rem;     /* 12px */
    --fs-sm: 0.8125rem;   /* 13px */
    --fs-base: 0.9375rem; /* 15px */
    --fs-md: 1rem;        /* 16px */
    --fs-lg: 1.125rem;    /* 18px */
    --fs-xl: 1.375rem;    /* 22px */
    --fs-2xl: 1.75rem;    /* 28px */
    --lh-base: 1.6;
    --lh-tight: 1.3;

    /* Shape & elevation — thang bo góc 3 bậc nhất quán + bóng nhiều lớp, rất nhạt,
       ám sắc thương hiệu (indigo) thay cho xám trung tính (phong cách 2026). */
    --radius-sm: 12px;
    --radius: 16px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(31, 38, 88, .05);
    --shadow: 0 1px 2px rgba(31, 38, 88, .04), 0 6px 16px rgba(40, 46, 99, .07);
    --shadow-md: 0 2px 6px rgba(31, 38, 88, .06), 0 14px 32px rgba(40, 46, 99, .10);
    --shadow-lg: 0 14px 40px rgba(40, 46, 99, .14);
    --shadow-glow: 0 6px 20px rgba(79, 70, 229, .22);

    --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-base);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    background-color: var(--bg);
}
/* Flat 2026: nền phẳng đặc, không aurora/gradient nền (đã bỏ glassmorphism). */

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: var(--lh-tight);
    letter-spacing: -.015em;
    color: #141724;
}
h5 { font-size: var(--fs-lg); }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* Accessibility: viền focus rõ ràng khi dùng bàn phím (không hiện khi click chuột) */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.btn:focus-visible, .page-link:focus-visible, .form-control:focus-visible, .form-select:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px;
}
.sidebar-nav .nav-link:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }

/* ---- App shell ---------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(185deg, #1b2140 0%, #141a33 55%, #0e1226 100%);
    color: var(--sidebar-fg);
    position: fixed; inset: 0 auto 0 0; z-index: 1040;
    display: flex; flex-direction: column;
    transition: transform .25s ease;
    border-right: 1px solid rgba(255, 255, 255, .06);
    box-shadow: 4px 0 30px rgba(14, 18, 38, .25);
}
.sidebar-brand {
    padding: 22px 22px; font-size: var(--fs-lg); font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, .07); color: #fff;
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    letter-spacing: -.01em;
}
.sidebar-brand i {
    background: var(--grad-accent);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.sidebar-close { background: none; border: none; color: #94a3b8; font-size: 1.1rem; cursor: pointer; }
.sidebar-nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.sidebar-nav .nav-link {
    color: var(--sidebar-fg); padding: 11px 14px; border-radius: 12px;
    display: flex; gap: 12px; align-items: center; text-decoration: none;
    font-size: var(--fs-base); font-weight: 500; letter-spacing: -.01em;
    position: relative; transition: background .18s, color .18s, transform .18s;
}
.sidebar-nav .nav-link i { font-size: 1.1rem; width: 20px; text-align: center; opacity: .9; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; transform: translateX(2px); }
.sidebar-nav .nav-link.active {
    background: var(--primary); color: #fff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, .25);
}
.sidebar-nav .nav-link.active i { opacity: 1; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(2px); z-index: 1035; }
.sidebar-backdrop.show { display: block; }

.app-main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 13px 26px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 1020;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.sidebar-toggle { background: none; border: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: #374151; }
.sidebar-collapse-btn {
    background: var(--bg); border: 1px solid var(--border); color: #374151;
    font-size: 1.2rem; line-height: 1; cursor: pointer; width: 38px; height: 38px;
    border-radius: var(--radius-sm); align-items: center; justify-content: center; transition: background .15s, color .15s;
}
.sidebar-collapse-btn:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.topbar-title { font-weight: 600; font-size: var(--fs-md); letter-spacing: -.01em; }
.topbar-user {
    color: var(--text-muted); font-size: var(--fs-sm); display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg); border: 1px solid var(--border);
    padding: 5px 12px; border-radius: 999px; transition: background .15s, border-color .15s;
}
.topbar-user:hover { background: var(--primary-soft); border-color: var(--primary); }
.topbar-user i { color: var(--primary); font-size: 1rem; }

/* Language switcher */
.lang-switch .dropdown-toggle {
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    font-size: var(--fs-sm); font-weight: 500; padding: 6px 12px; border-radius: 999px;
    display: inline-flex; align-items: center; gap: 6px; transition: background .15s, border-color .15s;
}
.lang-switch .dropdown-toggle:hover { background: var(--primary-soft); border-color: var(--primary); }

/* Topbar dropdown menus (language + account) — đồng bộ với type-scale của design system,
   thay cho cỡ chữ/padding mặc định thô của Bootstrap. */
.topbar .dropdown-menu {
    --bs-dropdown-min-width: 11.5rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); background: #fff;
    padding: 6px; margin-top: 8px; font-size: var(--fs-base);
}
.topbar .dropdown-menu form { margin: 0; }
.topbar .dropdown-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    font-size: var(--fs-base); font-weight: 500; color: var(--text);
    padding: 9px 12px; border-radius: 9px; line-height: 1.25;
    letter-spacing: -.005em; transition: background .14s, color .14s;
}
.topbar .dropdown-item i { font-size: 1rem; width: 18px; text-align: center; color: var(--text-faint); }
.topbar .dropdown-item:hover, .topbar .dropdown-item:focus { background: var(--primary-soft); color: var(--primary); }
.topbar .dropdown-item:hover i, .topbar .dropdown-item:focus i,
.topbar .dropdown-item.active i { color: var(--primary); }
.topbar .dropdown-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.topbar .dropdown-divider { margin: 6px 4px; border-color: var(--border); }

.content { padding: 26px; }

/* ---- Flat surface (reusable) -------------------------------------------- */
.glass, .card, .filter-card, .stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ---- Cards & stats ------------------------------------------------------ */
.card { overflow: hidden; }
.card-header {
    border-bottom: 1px solid var(--border); font-size: var(--fs-base);
    background: #fff !important; font-weight: 600;
    padding: 15px 18px; letter-spacing: -.01em;
}
.card-body { position: relative; }

.stat-card {
    padding: 18px 20px;
    transition: box-shadow .18s, border-color .18s, transform .18s;
    position: relative; overflow: hidden;
}
.stat-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-2px); }
.stat-card .stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.stat-card .stat-valrow { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; line-height: 1.05; letter-spacing: -.035em; color: var(--text); }
.stat-card .stat-label { color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; margin-bottom: 6px; letter-spacing: 0; }

/* Delta badge: chiều mũi tên = hướng thay đổi, màu = tốt/xấu (đảo cho KPI Lỗi) */
.stat-delta {
    display: inline-flex; align-items: center; gap: 3px;
    font-size: var(--fs-xs); font-weight: 700; line-height: 1.4;
    padding: 1px 7px 1px 5px; border-radius: 999px; white-space: nowrap;
}
.stat-delta i { font-size: .92em; }
.stat-delta.is-good { color: var(--success); background: var(--success-tint); }
.stat-delta.is-bad  { color: var(--danger);  background: var(--danger-tint); }
.stat-delta.is-flat { color: var(--text-faint); background: var(--bg); }
.stat-icon {
    width: 40px; height: 40px; border-radius: 11px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.15rem; position: relative; z-index: 1;
}
.stat-icon.is-primary { background: var(--primary-tint); color: var(--primary); }
.stat-icon.is-accent  { background: var(--accent-tint);  color: var(--accent); }
.stat-icon.is-success { background: var(--success-tint); color: var(--success); }
.stat-icon.is-amber   { background: var(--amber-tint);   color: var(--warning); }
.stat-icon.is-danger  { background: var(--danger-tint);  color: var(--danger); }

/* KPI grid: CSS grid với các cột bằng nhau → card LUÔN đều nhau dù hàng cuối
   không lấp đầy (không bị giãn to như cách flex-grow trước đây). */
.kpi-grid { display: grid; gap: 16px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1199.98px) { .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 767.98px)  { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 419.98px)  { .kpi-grid { grid-template-columns: 1fr; } }

/* Stat card as a clickable link (KPI -> related screen) */
.stat-card { height: 100%; }
.stat-card.is-link { display: block; color: inherit; text-decoration: none; }
.stat-card.is-link:hover, .stat-card.is-link:focus { color: inherit; text-decoration: none; }
.stat-card .stat-go {
    position: absolute; right: 18px; bottom: 13px; z-index: 1; line-height: 1;
    color: var(--text-faint); font-size: .9rem;
    opacity: 0; transform: translateX(-5px); transition: opacity .2s, transform .2s;
}
.stat-card.is-link:hover .stat-go { opacity: 1; transform: translateX(0); }
.stat-card.is-alert { background: var(--danger-tint); border-color: rgba(225, 29, 72, .22); }
.stat-card.is-alert:hover { border-color: rgba(225, 29, 72, .4); }
.stat-card.is-alert .stat-value { color: var(--danger); }

/* KPI sparkline (inline SVG, colour via currentColor) */
.stat-spark { margin-top: 14px; height: 42px; }
.stat-spark .spark { display: block; width: 100%; height: 100%; overflow: visible; }
.spark-line { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark-area { fill: currentColor; opacity: .12; stroke: none; }
.spark-dot  { fill: currentColor; }

/* "View all" link inside card headers */
.card-link {
    font-size: var(--fs-sm); font-weight: 600; color: var(--primary);
    display: inline-flex; align-items: center; gap: 2px; white-space: nowrap;
}
.card-link:hover { color: var(--primary-hover); text-decoration: none; }
.card-link i { font-size: .78em; }

/* Page hero (title + subtitle + quick actions) */
.page-hero {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-hero .hero-text { min-width: 0; }
.page-hero .hero-title { font-size: 1.6rem; font-weight: 700; margin: 0; letter-spacing: -.03em; }
.page-hero .hero-sub { color: var(--text-muted); font-size: var(--fs-base); margin: 4px 0 0; }
.page-hero .hero-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 575.98px) {
    .page-hero { align-items: stretch; }
    .page-hero .hero-actions { width: 100%; }
    .page-hero .hero-actions .btn { flex: 1; }
}

.filter-card { padding: 16px 18px; margin-bottom: 18px; }
.filter-card .form-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
.filter-card .row { --bs-gutter-y: .6rem; }

/* Compact + expandable filter */
.filter-bar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filter-bar .filter-search { flex: 1 1 240px; min-width: 0; }
.filter-toggle .bi-chevron-down { transition: transform .18s; font-size: .75em; }
.filter-toggle.is-open .bi-chevron-down { transform: rotate(180deg); }
.filter-advanced { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

/* Bulk action bar (hiện khi chọn dòng) */
.bulk-bar {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    background: var(--primary); color: #fff;
    border-radius: var(--radius-sm); padding: 9px 8px 9px 16px; margin-bottom: 14px;
    box-shadow: var(--shadow-md);
}
.bulk-bar .bulk-count { font-size: var(--fs-sm); font-weight: 500; }
.bulk-bar .bulk-count strong { font-weight: 700; }
.bulk-bar .bulk-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bulk-bar .btn { background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .55); color: #fff; box-shadow: none; }
.bulk-bar .btn:hover { background: #fff; color: var(--primary); border-color: #fff; }
.bulk-bar .bulk-clear { margin-left: auto; background: none; border: none; color: rgba(255, 255, 255, .85); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 0 8px; }
.bulk-bar .bulk-clear:hover { color: #fff; }

/* Checkbox column */
.table th.col-check, .table td.col-check { width: 42px; padding-right: 0; text-align: center; }
.table .form-check-input { cursor: pointer; margin: 0; width: 1.05em; height: 1.05em; }
.table .form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
@media (max-width: 767.98px) { .table-cards .col-check { display: none; } }

/* ---- Invoice flagship: summary bar, quick chips, quick-view drawer ------- */
.summary-bar { display: flex; flex-wrap: wrap; gap: 10px; }
.summary-item {
    flex: 1 1 150px; min-width: 128px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow-sm);
}
.summary-item .summary-label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 500; }
.summary-item .summary-value { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.summary-item.is-primary { background: var(--primary-tint); border-color: rgba(79, 70, 229, .18); }
.summary-item.is-primary .summary-value { color: var(--primary); }

/* Custom flat select (thay popup <select> gốc của OS) */
.cselect { position: relative; display: block; }
.cselect-native { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; opacity: 0; pointer-events: none; }
.cselect-btn { text-align: left; cursor: pointer; width: 100%; }
.cselect-menu {
    position: absolute; top: calc(100% + 5px); left: 0; min-width: 100%;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); padding: 5px; z-index: 1060;
    max-height: 280px; overflow-y: auto; display: none;
}
.cselect.open .cselect-menu { display: block; }
.cselect.up .cselect-menu { top: auto; bottom: calc(100% + 5px); }
.cselect-inline { display: inline-block; min-width: 84px; vertical-align: middle; }
.cselect-item { padding: 7px 11px; border-radius: 8px; font-size: var(--fs-sm); color: var(--text); cursor: pointer; white-space: nowrap; transition: background .1s, color .1s; }
.cselect-item:hover { background: var(--primary-tint); color: var(--primary); }
.cselect-item.active { background: var(--primary); color: #fff; font-weight: 500; }

.quick-chips { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.quick-chips .chips-label { font-size: var(--fs-sm); color: var(--text-muted); }
.quick-chips .chip {
    border: 1px solid var(--border-strong); background: #fff; color: var(--text);
    font-size: var(--fs-sm); font-weight: 500; border-radius: 999px; padding: 4px 13px; cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.quick-chips .chip:hover { border-color: var(--primary); color: var(--primary); }
.quick-chips .chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.drawer { position: fixed; inset: 0; z-index: 1090; visibility: hidden; }
.drawer.open { visibility: visible; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); opacity: 0; transition: opacity .2s; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
    position: absolute; top: 0; right: 0; height: 100%; width: 560px; max-width: 94vw;
    background: var(--surface); box-shadow: -12px 0 40px rgba(15, 23, 42, .2);
    display: flex; flex-direction: column; transform: translateX(100%); transition: transform .25s ease;
}
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.drawer-close { background: none; border: none; font-size: 1.1rem; color: var(--text-muted); cursor: pointer; line-height: 1; }
.drawer-close:hover { color: var(--text); }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.drawer-dl { display: grid; grid-template-columns: 132px 1fr; gap: 6px 12px; margin: 0 0 18px; }
.drawer-dl dt { color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; }
.drawer-dl dd { margin: 0; font-size: var(--fs-sm); color: var(--text); min-width: 0; overflow: hidden; }
.drawer-section-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 600; margin-bottom: 8px; }
.drawer-preview { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }
.drawer-nopreview { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 36px 16px; text-align: center; color: var(--text-faint); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.drawer-nopreview i { font-size: 2rem; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
body.drawer-open { overflow: hidden; }
@media (max-width: 575.98px) { .drawer-dl { grid-template-columns: 108px 1fr; } }

/* ---- Tables ------------------------------------------------------------- */
.table { font-size: var(--fs-sm); --bs-table-bg: transparent; margin-bottom: 0; border-collapse: separate; border-spacing: 0; }
.table thead th {
    font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-faint); font-weight: 600; border-bottom: 1px solid var(--border);
    background: #fafbfe; padding: 10px 14px; white-space: nowrap;
    position: sticky; top: 0;
}
.table td { vertical-align: middle; font-size: var(--fs-sm); color: var(--text); border-bottom: 1px solid var(--border); border-top: 0; padding: 10px 14px; white-space: nowrap; }
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-hover tbody tr { transition: background .12s; }
.table-hover tbody tr:nth-child(even) { background: #fafbfd; }
.table-hover tbody tr:hover { background: var(--primary-tint); }
.table-responsive { border-radius: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Entity-list tables: the primary column absorbs slack so columns pack tidily, no big gaps.
   Skip the checkbox column — when present, the column right after it is the primary one. */
.table-pack th:first-child:not(.col-check), .table-pack td:first-child:not(.col-check) { width: 100%; }
.table-pack th.col-check + th, .table-pack td.col-check + td { width: 100%; }

/* ---- Dashboard preview tables: fixed columns + ellipsis (md+) ----------- */
@media (min-width: 768px) {
    .dash-table { table-layout: fixed; }
    .dash-table th,
    .dash-table td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .dash-table td a { color: var(--primary); }
    .dash-table .w-received { width: 152px; }
    .dash-table .w-status   { width: 124px; }
    .dash-table .w-date     { width: 112px; }
    .dash-table .w-total    { width: 136px; }
}

/* Nút thao tác trong bảng: icon ghost, gọn, không lệch hàng */
.table td .btn.btn-sm { width: 30px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; line-height: 1; margin: 0 1px; vertical-align: middle; }
.table td .btn.btn-sm:not(.btn-toggle) { border-color: transparent; background: transparent; box-shadow: none; }
.table td .btn.btn-sm:not(.btn-toggle):hover { background: rgba(30, 34, 48, .06); border-color: transparent; }
.table td .btn.btn-sm i { font-size: .95rem; }
.table td form.d-inline { vertical-align: middle; }
/* Nút toggle có chữ (Bật/Tắt) không bị ép vuông như nút icon */
.table td .btn.btn-sm.btn-toggle { width: auto; height: 32px; padding: 0 10px; gap: 5px; }

/* Ô "Hòm thư": icon nhà cung cấp + tên + email + hộp thư dùng chung gom 1 cột */
.mailbox-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.provider-chip {
    flex: 0 0 36px; width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; font-size: 1.05rem;
    background: var(--bg); border: 1px solid var(--border);
}
.provider-chip.p-gmail { color: #ea4335; }
.provider-chip.p-ms { color: #0078d4; }
.provider-chip.p-imap { color: var(--text-muted); }
.mailbox-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.mailbox-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-email { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailbox-shared { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge-status { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .02em; padding: .4em .7em; border-radius: 999px; }
.badge { border-radius: 999px; font-weight: 600; }

.empty-state { text-align: center; color: var(--text-faint); padding: 48px 16px; }
.empty-state i { font-size: 2.6rem; display: block; margin-bottom: 12px; opacity: .5; }

/* ---- Forms & buttons ---------------------------------------------------- */
.form-label { font-family: var(--font-sans); font-size: var(--fs-base); font-weight: 600; color: #2d3344; margin-bottom: 6px; letter-spacing: -.005em; }
.form-control, .form-select {
    font-family: var(--font-sans); font-size: var(--fs-base); line-height: 1.5;
    border-color: var(--border);
    background: rgba(255, 255, 255, .7); border-radius: 10px; padding: .5rem .75rem;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.form-control::placeholder { color: var(--text-faint); opacity: 1; }
.form-control-sm, .form-select-sm { border-radius: 8px; }
.form-control:focus, .form-select:focus {
    border-color: var(--primary); background: #fff;
    box-shadow: 0 0 0 .22rem rgba(79, 70, 229, .16);
}

.btn { font-family: var(--font-sans); font-size: var(--fs-base); font-weight: 500; border-radius: 10px; transition: transform .12s, box-shadow .15s, background .15s; }
.btn:active { transform: translateY(1px); }
.btn-sm { font-size: var(--fs-sm); border-radius: 8px; }
.btn-primary {
    background: var(--primary); border: 1px solid var(--primary); color: #fff;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); box-shadow: var(--shadow-sm); color: #fff; }
.btn-outline-primary { border-color: var(--border-strong); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-secondary { background: #fff; border: 1px solid var(--border-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: #fafbff; color: var(--text); border-color: var(--text-faint); }
/* Outline icon buttons in tables: softer, pill-grouped feel */
.text-nowrap .btn + .btn { margin-left: 4px; }

.ajax-loader { position: fixed; inset: 0; background: rgba(238, 241, 251, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 1080; }

.pagination { margin-bottom: 0; }
.page-link { color: var(--primary); border: none; background: transparent; border-radius: 8px; margin: 0 2px; }
.page-link:hover { background: var(--primary-soft); color: var(--primary-hover); }
.page-item.active .page-link { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.page-item.disabled .page-link { color: var(--text-faint); background: transparent; }

/* Thanh phân trang + chọn số dòng/trang */
.pager-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.pager-info { display: inline-flex; align-items: center; gap: 7px; color: var(--text-muted); font-size: var(--fs-sm); }
.pager-info .pager-sep { opacity: .5; }
.pager-size { width: auto; min-width: 72px; display: inline-block; }

/* Detail definition lists */
dl.row dt { color: var(--text-muted); font-weight: 600; font-size: var(--fs-sm); }
dl.row dd { color: var(--text); }

/* ---- Auth (flat 2026) --------------------------------------------------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 16px; position: relative; overflow: hidden;
    background:
        radial-gradient(at 100% 0%, rgba(99, 102, 241, .07) 0px, transparent 42%),
        radial-gradient(at 0% 100%, rgba(6, 182, 212, .05) 0px, transparent 42%),
        var(--bg);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 36px 32px; width: 100%; max-width: 412px;
    box-shadow: var(--shadow-md); color: var(--text);
}
.auth-brand { text-align: center; font-size: var(--fs-xl); font-weight: 700; margin-bottom: 6px; color: var(--text); }
.auth-brand i { color: var(--primary); }
.auth-sub { text-align: center; color: var(--text-muted); font-size: var(--fs-sm); margin-bottom: 26px; }
.auth-card .form-check-label { font-size: var(--fs-sm); }
.auth-lang { text-align: center; margin-top: 20px; font-size: var(--fs-sm); }
.auth-lang a { margin: 0 6px; color: var(--text-muted); }
.auth-lang a.text-muted { color: var(--text-faint) !important; }

/* ---- Desktop (lg+): thu gọn sidebar thành thanh icon ------------------- */
@media (min-width: 992px) {
    html.sidebar-collapsed .sidebar { width: 74px; }
    html.sidebar-collapsed .app-main { margin-left: 74px; }
    html.sidebar-collapsed .sidebar .brand-label,
    html.sidebar-collapsed .sidebar .nav-text { display: none; }

    /* Brand thu về 1 ô vuông gradient gọn gàng, căn giữa */
    html.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 18px 0; }
    html.sidebar-collapsed .sidebar-brand .brand-mark {
        width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center;
        font-size: 1.25rem; border-radius: 12px;
        background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .08);
    }

    /* Mỗi mục là 1 nút vuông căn giữa rail, không còn pill kéo dài toàn chiều ngang */
    html.sidebar-collapsed .sidebar-nav { padding: 14px 0; align-items: center; gap: 6px; overflow: visible; }
    html.sidebar-collapsed .sidebar-nav .nav-link {
        width: 46px; height: 46px; padding: 0; gap: 0;
        justify-content: center; border-radius: 13px;
    }
    html.sidebar-collapsed .sidebar-nav .nav-link i { width: auto; font-size: 1.2rem; }
    html.sidebar-collapsed .sidebar-nav .nav-link:hover { transform: none; }

    /* Active: thêm thanh chỉ báo nhỏ bên trái cho rõ trạng thái */
    html.sidebar-collapsed .sidebar-nav .nav-link.active::before {
        content: ""; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
        width: 3px; height: 22px; border-radius: 0 3px 3px 0; background: var(--accent, #fff);
    }

    /* Tooltip nhãn khi hover (thay tooltip mặc định của trình duyệt cho mượt) */
    html.sidebar-collapsed .sidebar-nav .nav-link .nav-text {
        display: block; position: absolute; left: calc(100% + 14px); top: 50%; transform: translateY(-50%);
        background: #0e1226; color: #fff; padding: 6px 11px; border-radius: 8px;
        font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; letter-spacing: -.01em;
        border: 1px solid rgba(255, 255, 255, .1); box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
        opacity: 0; pointer-events: none; visibility: hidden;
        transition: opacity .15s ease, transform .15s ease; z-index: 1050;
    }
    html.sidebar-collapsed .sidebar-nav .nav-link .nav-text::before {
        content: ""; position: absolute; right: 100%; top: 50%; transform: translateY(-50%);
        border: 5px solid transparent; border-right-color: #0e1226;
    }
    html.sidebar-collapsed .sidebar-nav .nav-link:hover .nav-text {
        opacity: 1; visibility: visible; transform: translateY(-50%) translateX(2px);
    }
}

/* ---- Responsive: collapse sidebar under lg (992px) ---------------------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .content { padding: 20px; }
}

/* ---- Responsive polish: topbar / headers / spacing --------------------- */
@media (max-width: 767.98px) {
    .content { padding: 16px 14px; }
    .topbar { padding: 10px 14px; }
    .topbar-right { gap: 8px; }
    .topbar-title { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .page-head { flex-wrap: wrap; gap: 10px; }
}
@media (max-width: 575.98px) {
    .topbar-user { display: none; }
    .lang-switch .dropdown-toggle .lang-label { display: none; }
    .stat-card { padding: 16px 18px; }
    .stat-card .stat-value { font-size: var(--fs-xl); }
    .filter-card { padding: 16px; }
    .pager-bar { justify-content: center; }
    .pagination { justify-content: center; }
}

/* ---- Mobile card-view tables (< md) ------------------------------------ */
@media (max-width: 767.98px) {
    /* Khung bảng trở nên trong suốt; mỗi dòng tự là một thẻ */
    .table-card-host {
        background: transparent; border: none; box-shadow: none;
        -webkit-backdrop-filter: none; backdrop-filter: none; border-radius: 0; overflow: visible;
    }
    .table-card-host .card-body { padding: 0 !important; }
    .table-card-host .card-header {
        background: transparent !important; border: none; padding: 0 2px 12px;
        font-size: var(--fs-base); color: var(--text);
    }
    .table-card-host .table-responsive { overflow: visible; }

    .table-cards thead { display: none; }
    .table-cards tbody { display: block; }
    .table-cards tbody tr {
        display: block;
        /* Nền đặc thay vì backdrop-filter: nhẹ GPU hơn khi có nhiều dòng trên mobile */
        background: #ffffff;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        padding: 6px 16px; margin-bottom: 12px;
    }
    .table-cards.table-hover tbody tr:nth-child(even),
    .table-cards.table-hover tbody tr:hover { background: #ffffff; }
    .table-cards tbody td {
        display: flex; align-items: center; justify-content: space-between; gap: 14px;
        border: 0; border-top: 1px dashed rgba(230, 232, 240, .9); padding: 9px 0;
        font-size: var(--fs-sm); max-width: none !important; white-space: normal; text-align: right;
    }
    .table-cards tbody tr td:first-child { border-top: 0; }
    .table-cards tbody td::before {
        content: attr(data-label); flex: 0 0 38%; text-align: left;
        font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
        color: var(--text-muted); white-space: nowrap;
    }
    .table-cards tbody td.text-truncate { overflow: visible; text-overflow: clip; }
    /* Ô thao tác: nhãn trái, nhóm nút gom lại (không dàn rải rác) */
    .table-cards tbody td.text-end { justify-content: flex-start; flex-wrap: wrap; gap: 4px; }
    .table-cards tbody td.text-end::before { flex: 0 0 38%; }
    /* Hàng "không có dữ liệu" trải dài, không tách nhãn */
    .table-cards tbody td[colspan] { display: block; text-align: center; border-top: 0; padding: 0; }
    .table-cards tbody td[colspan]::before { display: none; }
    .table-cards tbody tr:has(td[colspan]) {
        background: var(--surface); padding: 0;
    }
}

/* ============================================================
   OAuth settings screen (provider connection cards)
   ============================================================ */
.oauth-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
@media (max-width: 860px) {
    .oauth-grid { grid-template-columns: 1fr; }
}

.oauth-card { position: relative; overflow: hidden; transition: transform .18s ease, box-shadow .18s ease; }
.oauth-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.oauth-card::before {
    content: "";
    position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: var(--brand-grad, var(--grad-primary));
}
.oauth-card .card-body { padding: 22px 20px 18px; }

/* brand accents */
.oauth-card.brand-google { --brand-grad: linear-gradient(135deg, #4285F4 0%, #34A853 42%, #FBBC05 72%, #EA4335 100%); }
.oauth-card.brand-microsoft { --brand-grad: linear-gradient(135deg, #2b88d8 0%, #0078D4 55%, #005A9E 100%); }

.oauth-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.oauth-head-text { min-width: 0; }
.oauth-logo {
    flex: 0 0 auto;
    width: 46px; height: 46px;
    border-radius: 14px;
    display: grid; place-items: center;
    font-size: 1.5rem; color: #fff;
    background: var(--brand-grad, var(--grad-primary));
    box-shadow: var(--shadow-sm);
}
.oauth-title { font-weight: 700; font-size: var(--fs-lg); line-height: 1.15; color: var(--text); }
.oauth-sub { font-size: var(--fs-xs); color: var(--text-muted); }

.oauth-pill {
    margin-left: auto; flex: 0 0 auto;
    display: inline-flex; align-items: center; gap: 6px;
    font-size: var(--fs-xs); font-weight: 600;
    padding: .4em .75em; border-radius: 999px; white-space: nowrap;
}
.oauth-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.oauth-pill.is-on { color: #0f7a43; background: rgba(22, 163, 74, .12); }
.oauth-pill.is-on .dot { background: #16a34a; animation: oauthPulse 1.9s infinite; }
.oauth-pill.is-off { color: var(--text-muted); background: rgba(107, 113, 133, .12); }
.oauth-pill.is-off .dot { background: var(--text-faint); }
.oauth-pill.is-saved { color: var(--warning); background: rgba(217, 119, 6, .12); }
.oauth-pill.is-saved .dot { background: var(--warning); }
.oauth-pill.is-bad { color: var(--danger); background: rgba(225, 29, 72, .12); }
.oauth-pill.is-bad .dot { background: var(--danger); }
@keyframes oauthPulse {
    0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .45); }
    70% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

.oauth-redirect {
    background: var(--primary-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px; margin-bottom: 16px;
}
.oauth-redirect .lbl {
    font-size: var(--fs-xs); color: var(--text-muted);
    display: flex; align-items: center; gap: 6px; margin-bottom: 5px;
}
.oauth-uri { display: flex; align-items: center; gap: 8px; }
.oauth-uri code {
    flex: 1; min-width: 0;
    font-size: var(--fs-xs); color: var(--primary);
    background: transparent; padding: 0; overflow-wrap: anywhere;
}
.oauth-copy {
    flex: 0 0 auto;
    width: 30px; height: 30px;
    border: 1px solid var(--border); background: var(--surface);
    border-radius: 8px; color: var(--text-muted); cursor: pointer;
    display: grid; place-items: center; transition: .15s;
}
.oauth-copy:hover { color: var(--primary); border-color: var(--primary); }
.oauth-copy.copied { color: var(--success); border-color: var(--success); }

.oauth-field { margin-bottom: 13px; }
.oauth-field > label {
    font-size: var(--fs-sm); font-weight: 600; color: var(--text);
    margin-bottom: 5px; display: flex; align-items: center; gap: 6px;
}
.oauth-field > label i { color: var(--text-muted); }
.oauth-input-wrap { position: relative; }
.oauth-input-wrap .form-control { padding-right: 38px; }
.oauth-input-wrap .toggle-secret {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-faint);
    cursor: pointer; padding: 4px 6px; line-height: 1;
}
.oauth-input-wrap .toggle-secret:hover { color: var(--primary); }

.oauth-actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.oauth-updated { font-size: var(--fs-xs); color: var(--text-faint); margin-left: auto; display: inline-flex; align-items: center; gap: 5px; }

.oauth-verify-result {
    margin-top: 12px; padding: 9px 12px;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    font-size: var(--fs-sm); font-weight: 500;
    display: flex; align-items: center; gap: 8px;
}
.oauth-verify-result.is-ok { color: #0f7a43; background: rgba(22, 163, 74, .08); border-color: rgba(22, 163, 74, .25); }
.oauth-verify-result.is-err { color: var(--danger); background: rgba(225, 29, 72, .07); border-color: rgba(225, 29, 72, .25); }
.oauth-verify-result i { font-size: 1rem; flex: 0 0 auto; }

/* Reduce-motion friendliness */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
    .oauth-pill.is-on .dot { animation: none; }
}
