/* =========================================================================
   CRM · Liquid Glass
   ========================================================================= */

:root {
	--font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--mono: ui-monospace, "SF Mono", Consolas, monospace;

	--bg: #eef1fb;
	--text: #0d1424;
	--text-2: #334155;
	--muted: #64748b;

	--glass: rgba(255, 255, 255, .48);
	--glass-2: rgba(255, 255, 255, .72);
	--glass-3: rgba(255, 255, 255, .32);
	--edge: rgba(255, 255, 255, .78);
	--line: rgba(15, 23, 42, .075);

	--hi: inset 0 1px 0 rgba(255, 255, 255, .95), inset 0 -1px 0 rgba(255, 255, 255, .35);
	--shadow: 0 1px 1px rgba(15, 23, 42, .03), 0 18px 40px -18px rgba(38, 48, 120, .28);
	--blur: blur(24px) saturate(185%);

	--primary: #4f46e5;
	--grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #d946ef 100%);
	--ok: #10b981;
	--warn: #f59e0b;
	--bad: #ef4444;

	--r-lg: 26px;
	--r: 18px;
	--r-sm: 12px;
}

[data-theme="dark"] {
	--bg: #090d1c;
	--text: #eef2ff;
	--text-2: #cbd5e1;
	--muted: #8f9bb3;
	--glass: rgba(24, 30, 54, .5);
	--glass-2: rgba(36, 43, 74, .7);
	--glass-3: rgba(255, 255, 255, .05);
	--edge: rgba(255, 255, 255, .12);
	--line: rgba(255, 255, 255, .08);
	--hi: inset 0 1px 0 rgba(255, 255, 255, .14), inset 0 -1px 0 rgba(255, 255, 255, .03);
	--shadow: 0 18px 44px -16px rgba(0, 0, 0, .65);
	--primary: #a5b4fc;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body.crm {
	margin: 0;
	min-height: 100vh;
	font: 400 14px/1.5 var(--font);
	color: var(--text);
	background: var(--bg);
	-webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; opacity: .9; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .9em; padding: 1px 6px; border-radius: 6px; background: var(--glass-3); border: 1px solid var(--line); }
.hgi { line-height: 1; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 13px; }
.ellipsis { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.push-right { margin-left: auto; }

/* ---------- Nền chuyển động ---------- */
.crm-bg {
	position: fixed;
	inset: 0;
	z-index: -1;
	overflow: hidden;
	background:
		radial-gradient(1100px 620px at 8% -12%, #c7d2fe 0, transparent 60%),
		radial-gradient(900px 620px at 108% 6%, #fbcfe8 0, transparent 58%),
		radial-gradient(1000px 700px at 50% 118%, #bae6fd 0, transparent 60%),
		var(--bg);
}
.crm-bg span {
	position: absolute;
	border-radius: 50%;
	filter: blur(70px);
	opacity: .5;
	animation: crm-float 26s ease-in-out infinite alternate;
	will-change: transform;
}
.crm-bg span:nth-child(1) { width: 440px; height: 440px; background: #818cf8; top: -120px; left: 22%; }
.crm-bg span:nth-child(2) { width: 380px; height: 380px; background: #f472b6; top: 30%; right: -80px; animation-duration: 32s; }
.crm-bg span:nth-child(3) { width: 420px; height: 420px; background: #38bdf8; bottom: -140px; left: -60px; animation-duration: 29s; }
.crm-bg span:nth-child(4) { width: 300px; height: 300px; background: #a78bfa; bottom: 10%; right: 28%; animation-duration: 36s; }
[data-theme="dark"] .crm-bg {
	background:
		radial-gradient(1000px 600px at 8% -12%, #1e1b4b 0, transparent 60%),
		radial-gradient(900px 620px at 108% 6%, #3b0a2f 0, transparent 58%),
		radial-gradient(1000px 700px at 50% 118%, #0c2a46 0, transparent 60%),
		var(--bg);
}
[data-theme="dark"] .crm-bg span { opacity: .28; }
@keyframes crm-float { to { transform: translate3d(70px, 50px, 0) scale(1.12); } }
@media (prefers-reduced-motion: reduce) { .crm-bg span { animation: none; } }

/* ---------- Kính ---------- */
.glass,
.glass-pill {
	position: relative;
	isolation: isolate;
	background: var(--glass);
	-webkit-backdrop-filter: var(--blur);
	backdrop-filter: var(--blur);
	border: 1px solid var(--edge);
	box-shadow: var(--shadow), var(--hi);
}
.glass { border-radius: var(--r-lg); }
.glass::before,
.glass-pill::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	border-radius: inherit;
	pointer-events: none;
	background:
		linear-gradient(140deg, rgba(255, 255, 255, .55) 0%, rgba(255, 255, 255, 0) 38%),
		linear-gradient(320deg, rgba(255, 255, 255, .22) 0%, rgba(255, 255, 255, 0) 30%);
}
[data-theme="dark"] .glass::before,
[data-theme="dark"] .glass-pill::before {
	background:
		linear-gradient(140deg, rgba(255, 255, 255, .08) 0%, rgba(255, 255, 255, 0) 38%),
		linear-gradient(320deg, rgba(255, 255, 255, .04) 0%, rgba(255, 255, 255, 0) 30%);
}
.glass-pill {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 8px 14px;
	border-radius: 999px;
	font-size: 13px;
	color: var(--text-2);
}
.glass-pill > .hgi { font-size: 18px; color: var(--primary); }

/* ---------- Layout ---------- */
.crm-app {
	display: grid;
	grid-template-columns: 264px minmax(0, 1fr);
	gap: 18px;
	padding: 18px;
	min-height: 100vh;
}
.crm-main { min-width: 0; display: flex; flex-direction: column; }
.crm-content { display: flex; flex-direction: column; gap: 18px; }

.crm-sidebar {
	position: sticky;
	top: 18px;
	height: calc(100vh - 36px);
	display: flex;
	flex-direction: column;
	padding: 18px 14px;
	overflow-y: auto;
	z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; color: var(--text); }
.brand-logo {
	width: 42px; height: 42px;
	display: grid; place-items: center;
	border-radius: 14px;
	color: #fff;
	font-size: 22px;
	background: var(--grad);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 10px 22px -10px rgba(99, 102, 241, .9);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 18px; letter-spacing: .02em; }
.brand-text small { color: var(--muted); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
	display: flex; align-items: center; gap: 12px;
	padding: 11px 14px;
	border-radius: 14px;
	color: var(--text-2);
	font-weight: 500;
	border: 1px solid transparent;
	transition: background .2s, color .2s, box-shadow .2s;
}
.nav a .hgi { font-size: 20px; }
.nav a:hover { background: var(--glass-3); opacity: 1; }
.nav a.active {
	color: var(--primary);
	background: var(--glass-2);
	border-color: var(--edge);
	box-shadow: var(--hi), 0 8px 20px -12px rgba(79, 70, 229, .55);
	font-weight: 600;
}
.nav .count {
	margin-left: auto;
	min-width: 22px; height: 22px; padding: 0 7px;
	display: grid; place-items: center;
	border-radius: 999px;
	font: 700 11px/1 var(--font);
	font-style: normal;
	color: #fff;
	background: linear-gradient(135deg, #f43f5e, #f97316);
}

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 16px; }
.pbx {
	display: flex; gap: 10px; align-items: center;
	padding: 10px 12px;
	border-radius: 14px;
	background: var(--glass-3);
	border: 1px solid var(--line);
	font-size: 12px;
}
.pbx strong { display: block; font-size: 12.5px; }
.pbx small { color: var(--muted); }
.pbx-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 4px rgba(245, 158, 11, .18); flex: none; }
.pbx.on .pbx-dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(16, 185, 129, .18); }
.me { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 16px; background: var(--glass-2); border: 1px solid var(--edge); box-shadow: var(--hi); }
.me-info { flex: 1; min-width: 0; line-height: 1.25; }
.me-info strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-info small { color: var(--muted); font-size: 11.5px; }

.crm-topbar {
	position: sticky;
	top: 18px;
	z-index: 30;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 12px 10px 20px;
	margin-bottom: 18px;
}
.page-title { min-width: 0; flex: 1; }
.page-title h1 { font-size: 20px; font-weight: 700; }
.page-title p { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-search { position: relative; width: min(320px, 32vw); }
.top-search .hgi { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 18px; }
.top-search input { width: 100%; padding-left: 42px; border-radius: 999px; }

.crm-overlay { display: none; }
.only-mobile, .only-sm { display: none !important; }
[data-theme="dark"] .i-dark, :root:not([data-theme="dark"]) .i-light { display: none; }

/* ---------- Nút ---------- */
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	height: 40px; padding: 0 16px;
	border-radius: 999px;
	border: 1px solid var(--edge);
	background: var(--glass-2);
	-webkit-backdrop-filter: blur(12px);
	backdrop-filter: blur(12px);
	color: var(--text);
	font: 600 13.5px/1 var(--font);
	white-space: nowrap;
	cursor: pointer;
	box-shadow: var(--hi), 0 6px 16px -10px rgba(15, 23, 42, .35);
	transition: transform .15s ease, box-shadow .2s, background .2s, opacity .2s;
}
.btn .hgi { font-size: 18px; }
.btn:hover { transform: translateY(-1px); opacity: 1; box-shadow: var(--hi), 0 10px 22px -12px rgba(15, 23, 42, .45); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn.loading { opacity: .6; pointer-events: none; }
.btn-primary {
	color: #fff;
	background: var(--grad);
	border-color: rgba(255, 255, 255, .35);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 12px 26px -12px rgba(99, 102, 241, .9);
}
.btn-ok {
	color: #fff;
	background: linear-gradient(135deg, #10b981, #0d9488);
	border-color: rgba(255, 255, 255, .35);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 12px 26px -12px rgba(16, 185, 129, .9);
}
.btn-warn {
	color: #fff;
	background: linear-gradient(135deg, #f59e0b, #f97316);
	border-color: rgba(255, 255, 255, .35);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 12px 26px -12px rgba(245, 158, 11, .9);
}
.btn-ghost { background: transparent; box-shadow: none; border-color: var(--line); -webkit-backdrop-filter: none; backdrop-filter: none; }
.btn-danger { color: var(--bad); }
.btn-soft { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); border-color: color-mix(in srgb, var(--primary) 22%, transparent); box-shadow: none; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn-sm .hgi { font-size: 16px; }
.btn-lg { height: 48px; font-size: 15px; }
.btn-block { width: 100%; }
.btn.loading::after {
	content: ""; width: 14px; height: 14px; border-radius: 50%;
	border: 2px solid currentColor; border-right-color: transparent;
	animation: crm-spin .7s linear infinite;
}
@keyframes crm-spin { to { transform: rotate(360deg); } }

.icon-btn {
	width: 40px; height: 40px; flex: none;
	display: inline-grid; place-items: center;
	border-radius: 50%;
	border: 1px solid var(--edge);
	background: var(--glass-2);
	color: var(--text-2);
	font-size: 19px;
	cursor: pointer;
	box-shadow: var(--hi), 0 6px 14px -10px rgba(15, 23, 42, .4);
	transition: transform .15s, color .2s;
}
.icon-btn:hover { color: var(--primary); transform: translateY(-1px); opacity: 1; }
.icon-btn-sm { width: 32px; height: 32px; font-size: 16px; }
.icon-btn.disabled { opacity: .35; pointer-events: none; }
.btn-call { color: var(--ok); }

.link { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; }

/* ---------- Form ---------- */
input, select, textarea { font: inherit; color: inherit; }
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) {
	height: 42px;
	padding: 0 14px;
	border-radius: 14px;
	border: 1px solid var(--line);
	background: var(--glass-2);
	color: var(--text);
	outline: none;
	box-shadow: inset 0 1px 2px rgba(15, 23, 42, .05);
	transition: border-color .2s, box-shadow .2s;
	min-width: 0;
}
:where(textarea) { height: auto; padding: 12px 14px; resize: vertical; line-height: 1.5; }
:where(select) { padding-right: 34px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; cursor: pointer; }
input:focus, select:focus, textarea:focus { border-color: color-mix(in srgb, var(--primary) 60%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent); }
input[readonly] { opacity: .85; }
[data-theme="dark"] input[type="date"] { color-scheme: dark; }
.select-sm { height: 34px !important; font-size: 13px; border-radius: 999px !important; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field small { font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text-2); cursor: pointer; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.input-icon { position: relative; display: flex; }
.input-icon .hgi { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 18px; pointer-events: none; }
.input-icon input { padding-left: 42px !important; width: 100%; }
.row-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Thành phần ---------- */
.grid { display: grid; gap: 18px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.kpis-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.cols-2 { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.card { padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.card-title .hgi { font-size: 20px; color: var(--primary); }

.hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 24px; flex-wrap: wrap; }
.hero h2 { font-size: 22px; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.hero h2 .hgi { color: #f59e0b; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.kpi { display: flex; gap: 14px; align-items: flex-start; padding: 18px; }
.kpi-icon {
	width: 46px; height: 46px; flex: none;
	display: grid; place-items: center;
	border-radius: 15px;
	font-size: 22px;
	color: #fff;
	background: linear-gradient(135deg, var(--c1), var(--c2));
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 10px 20px -10px var(--c1);
}
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin: 2px 0; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.badge {
	--c: #6366f1;
	display: inline-flex; align-items: center; gap: 5px;
	padding: 4px 10px;
	border-radius: 999px;
	font-size: 12px; font-weight: 600;
	white-space: nowrap;
	color: var(--c);
	background: color-mix(in srgb, var(--c) 13%, transparent);
	border: 1px solid color-mix(in srgb, var(--c) 24%, transparent);
	vertical-align: middle;
}
.badge .hgi { font-size: 14px; }
[data-theme="dark"] .badge { color: color-mix(in srgb, var(--c) 65%, #fff); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
	display: inline-flex; align-items: center; gap: 6px;
	padding: 6px 12px;
	border-radius: 999px;
	font-size: 12.5px; font-weight: 500;
	color: var(--text-2);
	background: var(--glass-2);
	border: 1px solid var(--edge);
	box-shadow: var(--hi);
	cursor: default;
}
button.chip { cursor: pointer; font-family: inherit; }
button.chip:hover { color: var(--primary); }
.chip .hgi { font-size: 15px; color: var(--muted); }
.chip-sm { padding: 3px 10px; font-size: 12px; }

.avatar {
	--h: 240;
	width: 34px; height: 34px; flex: none;
	display: inline-grid; place-items: center;
	border-radius: 50%;
	font-size: 12px; font-weight: 700;
	color: #fff;
	background: linear-gradient(135deg, hsl(var(--h) 78% 64%), hsl(calc(var(--h) + 45) 74% 52%));
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 0 0 2px var(--glass-2);
}
.avatar-xs { width: 24px; height: 24px; font-size: 9.5px; }
.avatar-lg { width: 60px; height: 60px; font-size: 20px; border-radius: 20px; }
.avatar-empty { background: var(--glass-3); color: var(--muted); border: 1px dashed var(--muted); box-shadow: none; font-size: 14px; }
.avatar-team { background: var(--grad); font-size: 16px; }

.person { display: inline-flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; }
.person > span:last-child { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.person small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.person-sm .avatar { width: 28px; height: 28px; font-size: 10.5px; }
.person-sm > span:last-child { font-size: 13px; }

.alert { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 16px; font-size: 13.5px; border: 1px solid transparent; }
.alert > .hgi { font-size: 20px; flex: none; }
.alert-ok { color: #047857; background: rgba(16, 185, 129, .12); border-color: rgba(16, 185, 129, .25); }
.alert-bad { color: #b91c1c; background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .22); }
.alert-warn { color: #b45309; background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .25); }
[data-theme="dark"] .alert-ok { color: #6ee7b7; }
[data-theme="dark"] .alert-bad { color: #fca5a5; }
[data-theme="dark"] .alert-warn { color: #fcd34d; }
.alert.glass { border-radius: var(--r-lg); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty > .hgi { font-size: 40px; opacity: .6; }
.empty.small { padding: 22px 10px; }
.empty.small > .hgi { font-size: 30px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.list-main a { color: var(--text); }
.list-main .muted { font-size: 12.5px; }
.rank { width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 8px; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--glass-3); border: 1px solid var(--line); }
.rank-1 { color: #fff; background: linear-gradient(135deg, #fbbf24, #f59e0b); border: 0; }
.rank-2 { color: #fff; background: linear-gradient(135deg, #cbd5e1, #94a3b8); border: 0; }
.rank-3 { color: #fff; background: linear-gradient(135deg, #fdba74, #ea580c); border: 0; }

.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: minmax(0, 170px) 1fr 32px; align-items: center; gap: 12px; font-size: 13px; color: var(--text-2); padding: 3px 6px; border-radius: 10px; }
a.funnel-row:hover { background: var(--glass-3); opacity: 1; }
.funnel-label { display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.funnel-label .hgi { color: var(--c); font-size: 16px; flex: none; }
.funnel-row b { text-align: right; color: var(--text); }
.bar { height: 9px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 55%, #fff)); box-shadow: 0 0 12px -2px var(--c); }

.chart-box { position: relative; height: 290px; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { height: 40px; border-radius: 999px; }
.filters .input-icon input { width: 220px; }
.date-field { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }

.seg {
	display: inline-flex; gap: 2px;
	padding: 4px;
	border-radius: 999px;
	background: var(--glass);
	-webkit-backdrop-filter: var(--blur);
	backdrop-filter: var(--blur);
	border: 1px solid var(--edge);
	box-shadow: var(--hi);
	overflow-x: auto;
	max-width: 100%;
	scrollbar-width: none;
}
.seg a { padding: 8px 15px; border-radius: 999px; color: var(--text-2); font-weight: 500; font-size: 13px; white-space: nowrap; transition: .2s; }
.seg a.active { color: var(--primary); background: var(--glass-2); font-weight: 600; box-shadow: var(--hi), 0 6px 14px -8px rgba(15, 23, 42, .3); }

.period-nav { padding: 4px; gap: 8px; }
.period-nav strong { display: inline-flex; align-items: center; gap: 8px; padding: 0 8px; color: var(--text); font-size: 13.5px; }

.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 34px; height: 34px; padding: 0 8px; display: grid; place-items: center; border-radius: 12px; color: var(--text-2); font-weight: 600; font-size: 13px; }
.pager a { background: var(--glass-3); border: 1px solid var(--line); }
.pager a.active { color: #fff; background: var(--grad); border-color: transparent; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; margin: 0 -8px; padding: 0 8px; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
.tbl th { padding: 10px 12px; text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr { transition: background .15s; }
.tbl tbody tr:hover td { background: var(--glass-3); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tfoot td { border-top: 2px solid var(--line); border-bottom: 0; font-weight: 600; background: color-mix(in srgb, var(--primary) 5%, transparent); }
.tbl .need { max-width: 260px; color: var(--text-2); }
.td-actions { white-space: nowrap; text-align: right; }
.td-actions .icon-btn + .icon-btn { margin-left: 4px; }
.tbl-report td { white-space: nowrap; }
.note { margin-top: 14px; }
.dir { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dir .hgi { font-size: 16px; }
.dir-in .hgi { color: var(--ok); }
.dir-out .hgi { color: #6366f1; }

/* ---------- Kanban ---------- */
.kanban {
	display: flex;
	gap: 14px;
	overflow-x: auto;
	padding: 4px 4px 18px;
	margin: 0 -4px;
	align-items: flex-start;
	scroll-snap-type: x proximity;
}
.kcol {
	flex: 0 0 286px;
	display: flex; flex-direction: column;
	max-height: calc(100vh - 210px);
	padding: 12px;
	scroll-snap-align: start;
	border-radius: 22px;
}
.kcol-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px 12px; }
.kicon { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 11px; font-size: 18px; color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border: 1px solid color-mix(in srgb, var(--c) 22%, transparent); }
.kcol-title { min-width: 0; line-height: 1.3; }
.kcol-title strong { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.kcol-title small { color: var(--muted); font-size: 12px; }
.kstep { width: 18px; height: 18px; display: inline-grid; place-items: center; border-radius: 6px; font-size: 10.5px; color: #fff; background: var(--c); }
.kcol-body {
	flex: 1;
	display: flex; flex-direction: column; gap: 10px;
	min-height: 90px;
	overflow-y: auto;
	padding: 2px;
	border-radius: 16px;
	transition: background .2s, outline-color .2s;
	outline: 2px dashed transparent;
	outline-offset: -2px;
}
.kcol-body.drag-over { background: color-mix(in srgb, var(--c) 10%, transparent); outline-color: color-mix(in srgb, var(--c) 55%, transparent); }
.kempty { display: none; padding: 18px 8px; text-align: center; color: var(--muted); font-size: 12.5px; border: 1px dashed var(--line); border-radius: 14px; }
.kempty .hgi { display: block; font-size: 22px; margin: 0 auto 4px; opacity: .6; }
.kcol-body:not(:has(.kcard)) .kempty { display: block; }
.kcard {
	display: block;
	padding: 12px 14px;
	border-radius: 16px;
	color: var(--text);
	background: var(--glass-2);
	border: 1px solid var(--edge);
	border-left: 3px solid var(--c);
	box-shadow: var(--hi), 0 8px 18px -14px rgba(15, 23, 42, .45);
	cursor: grab;
	transition: transform .15s, box-shadow .2s, opacity .2s;
}
.kcard:hover { transform: translateY(-2px); opacity: 1; box-shadow: var(--hi), 0 14px 26px -16px rgba(15, 23, 42, .55); }
.kcard.dragging { opacity: .45; transform: rotate(2deg) scale(.98); }
.kcard-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.kcard-top strong { font-size: 13.5px; line-height: 1.35; }
.kcard small { font-size: 12px; margin-top: 2px; }
.kcard-need { margin-top: 8px; padding: 6px 10px; border-radius: 10px; font-size: 12px; color: var(--text-2); background: var(--glass-3); border: 1px solid var(--line); }
.kcard-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.kcard-meta span { display: inline-flex; align-items: center; gap: 4px; }
.kcard-meta .hgi { font-size: 14px; }
.kcard-meta .warn { color: #d97706; }

/* ---------- Chi tiết khách hàng ---------- */
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: -6px; }
.lead-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 22px; flex-wrap: wrap; }
.lead-id { display: flex; gap: 16px; align-items: center; min-width: 0; }
.lead-id h2 { font-size: 21px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 8px; }
.lead-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.stepper { list-style: none; margin: 0; padding: 4px 0 6px; display: flex; overflow-x: auto; scrollbar-width: thin; }
.step { flex: 1 0 86px; position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; font-size: 11.5px; color: var(--muted); padding: 0 2px; }
.step::before { content: ""; position: absolute; top: 19px; right: 50%; width: 100%; height: 3px; background: var(--line); z-index: 0; }
.step:first-child::before { display: none; }
.step .dot { position: relative; z-index: 1; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; font-size: 18px; background: var(--glass-2); border: 1px solid var(--edge); box-shadow: var(--hi); color: var(--muted); }
.step-label { line-height: 1.3; }
.step.done { color: var(--text-2); }
.step.done::before, .step.current::before, .step.stopped::before { background: linear-gradient(90deg, #8b5cf6, var(--c)); }
.step.done .dot { color: #fff; background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 60%, #000)); border-color: transparent; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 6px 14px -6px var(--c); }
.step.current { color: var(--text); font-weight: 700; }
.step.current .dot { color: var(--c); background: var(--glass-2); border: 2px solid var(--c); animation: crm-pulse 2s infinite; }
.step.stopped .dot { color: var(--bad); border: 2px solid var(--bad); }
@keyframes crm-pulse {
	0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 45%, transparent); }
	70% { box-shadow: 0 0 0 12px transparent; }
	100% { box-shadow: 0 0 0 0 transparent; }
}
.stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.stage-q { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; margin-right: 4px; }
.stage-q .hgi { font-size: 20px; color: var(--primary); }
.stage-actions .alert { flex: 1 1 360px; }

.lead-grid { align-items: start; }
.note-form { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.note-form textarea { width: 100%; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: 12px; padding: 10px 0; }
.timeline li::before { content: ""; position: absolute; left: 17px; top: 50px; bottom: -8px; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.tl-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 12px; font-size: 17px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c) 20%, transparent); }
.tl-body { flex: 1; min-width: 0; font-size: 13.5px; padding-top: 2px; }
.tl-body a { font-weight: 600; }
.tl-time { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tl-note { margin-top: 6px; padding: 9px 12px; border-radius: 12px; background: var(--glass-3); border: 1px solid var(--line); white-space: pre-wrap; color: var(--text-2); }
.tl-link { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; margin-top: 4px; }
.timeline.compact li { padding: 7px 0; }
.timeline.compact li::before { top: 44px; }

.dl { display: grid; grid-template-columns: 130px 1fr; gap: 12px 14px; margin: 0; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; word-break: break-word; }

.msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.msg-bubble { display: inline-block; padding: 10px 14px; border-radius: 18px 18px 18px 6px; background: var(--glass-2); border: 1px solid var(--edge); box-shadow: var(--hi); }
.msg-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }

/* ---------- Cài đặt / nhập liệu ---------- */
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { flex: 1; }
.endpoints { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.endpoints li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--glass-3); border: 1px solid var(--line); }
.ep-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ep-main strong { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.ep-main code { background: none; border: 0; padding: 0; color: var(--muted); font-size: 12px; }
.method { flex: none; padding: 3px 8px; border-radius: 8px; font: 700 11px/1.4 var(--mono); color: #fff; }
.method-post { background: #10b981; }
.method-get { background: #0ea5e9; }
.code { margin: 16px 0 0; padding: 14px 16px; border-radius: 16px; background: rgba(13, 20, 36, .88); color: #dbe4ff; font: 12.5px/1.6 var(--mono); overflow: auto; max-height: 340px; white-space: pre-wrap; word-break: break-all; border: 1px solid rgba(255, 255, 255, .08); }
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; padding: 14px; border-radius: 16px; border: 1px dashed color-mix(in srgb, var(--bad) 40%, transparent); }

.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 16px; text-align: center; border-radius: 18px; border: 2px dashed color-mix(in srgb, var(--primary) 35%, transparent); background: color-mix(in srgb, var(--primary) 5%, transparent); cursor: pointer; transition: .2s; }
.dropzone:hover, .dropzone.over { background: color-mix(in srgb, var(--primary) 10%, transparent); border-color: var(--primary); }
.dropzone > .hgi { font-size: 34px; color: var(--primary); }
.dropzone input { display: none; }

.flow { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.flow li { display: flex; gap: 12px; align-items: flex-start; }
.flow li > span { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 12px; font-size: 18px; color: #fff; background: var(--grad); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45); }
.flow p { font-size: 13px; }

/* ---------- Modal & toast ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .28); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.modal.open { display: flex; animation: crm-fade .2s ease; }
.modal-box { width: min(600px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; background: var(--glass-2); animation: crm-pop .28s cubic-bezier(.2, .9, .3, 1.2); }
.modal-sm { width: min(460px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 17px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
#prompt-chips { margin-bottom: 12px; }
#prompt-chips:empty { display: none; }
@keyframes crm-fade { from { opacity: 0; } }
@keyframes crm-pop { from { opacity: 0; transform: translateY(14px) scale(.97); } }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; max-width: 380px; border-radius: 16px; font-size: 13.5px; font-weight: 500; background: var(--glass-2); pointer-events: auto; animation: crm-toast .35s cubic-bezier(.2, .9, .3, 1.2); }
.toast > .hgi { font-size: 20px; flex: none; }
.toast.ok > .hgi { color: var(--ok); }
.toast.err > .hgi { color: var(--bad); }
.toast.out { opacity: 0; transform: translateX(20px); transition: .3s; }
@keyframes crm-toast { from { opacity: 0; transform: translateY(16px) scale(.96); } }

/* ---------- Đăng nhập ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); padding: 30px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 24px; }
.brand-lg { padding: 0 0 4px; }
.brand-lg .brand-logo { width: 52px; height: 52px; font-size: 26px; border-radius: 17px; }
.demo-accounts { padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 10px; }
.demo-accounts p { display: flex; align-items: center; gap: 6px; }

/* ---------- Thanh điều hướng dưới (điện thoại) ---------- */
.bottom-nav { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
	.cols-3 { grid-template-columns: 1fr 1fr; }
	.cols-3 > :last-child { grid-column: span 2; }
}

@media (max-width: 1100px) {
	.cols-2 { grid-template-columns: 1fr; }
	.top-search { display: none; }
}

@media (max-width: 960px) {
	.crm-app { grid-template-columns: 1fr; padding: 12px 12px 100px; gap: 12px; }
	.crm-sidebar {
		position: fixed;
		top: 12px; left: 12px; bottom: 12px;
		width: 280px; height: auto;
		transform: translateX(calc(-100% - 24px));
		transition: transform .35s cubic-bezier(.2, .9, .3, 1);
		z-index: 90;
		background: var(--glass-2);
	}
	body.sidebar-open .crm-sidebar { transform: none; }
	.crm-overlay { position: fixed; inset: 0; z-index: 80; background: rgba(15, 23, 42, .3); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
	body.sidebar-open .crm-overlay { display: block; }
	.only-mobile { display: inline-grid !important; }
	.crm-topbar { top: 12px; padding: 8px 8px 8px 8px; margin-bottom: 12px; border-radius: 22px; }
	.crm-content { gap: 12px; }
	.grid { gap: 12px; }

	.bottom-nav {
		position: fixed;
		left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
		z-index: 70;
		display: grid;
		grid-template-columns: repeat(5, 1fr);
		padding: 6px;
		border-radius: 24px;
	}
	.bottom-nav a, .bottom-nav button {
		display: flex; flex-direction: column; align-items: center; gap: 3px;
		padding: 7px 2px;
		border: 0; border-radius: 18px;
		background: none;
		color: var(--muted);
		font: 500 10.5px/1.2 var(--font);
		cursor: pointer;
	}
	.bottom-nav .hgi { font-size: 21px; }
	.bottom-nav a.active { color: var(--primary); background: var(--glass-2); box-shadow: var(--hi); font-weight: 600; }

	.kcol { flex-basis: 82vw; max-height: none; }
	.kcol-body { max-height: 62vh; }
}

@media (max-width: 760px) {
	body.crm { font-size: 13.5px; }
	.page-title h1 { font-size: 17px; }
	.page-title p { display: none; }
	.hide-sm { display: none !important; }
	.only-sm { display: inline-grid !important; }
	.cols-3 { grid-template-columns: 1fr; }
	.cols-3 > :last-child { grid-column: auto; }
	.kpis, .kpis-4 { grid-template-columns: 1fr 1fr; }
	.kpi { flex-direction: column; gap: 10px; padding: 14px; }
	.kpi-icon { width: 38px; height: 38px; font-size: 19px; border-radius: 12px; }
	.kpi-value { font-size: 22px; }
	.card { padding: 16px; }
	.hero { padding: 18px; }
	.hero h2 { font-size: 18px; }
	.chart-box { height: 240px; }
	.form-grid { grid-template-columns: 1fr; }
	.form-grid .span-2 { grid-column: auto; }
	.filters { width: 100%; }
	.filters > * { flex: 1 1 140px; }
	.filters .input-icon input { width: 100%; }
	.toolbar .push-right { margin-left: 0; }
	.funnel-row { grid-template-columns: minmax(0, 130px) 1fr 28px; }
	.dl { grid-template-columns: 1fr; gap: 2px; }
	.dl dd { margin-bottom: 10px; }
	.lead-head { padding: 16px; }
	.lead-id { flex-direction: column; align-items: flex-start; gap: 12px; }
	.lead-id h2 { font-size: 19px; }
	.lead-actions { width: 100%; }
	.lead-actions .btn { flex: 1; }
	.stage-actions .btn { flex: 1 1 auto; }
	.stage-actions .push-right { margin-left: 0; }

	.modal { align-items: flex-end; padding: 0; }
	.modal-box { width: 100%; max-height: 90vh; border-radius: 26px 26px 0 0; padding-bottom: max(22px, env(safe-area-inset-bottom)); animation: crm-sheet .3s cubic-bezier(.2, .9, .3, 1); }
	@keyframes crm-sheet { from { transform: translateY(100%); } }
	.toasts { left: 12px; right: 12px; bottom: 96px; }
	.toast { max-width: none; }

	.tbl-cards thead { display: none; }
	.tbl-cards, .tbl-cards tbody, .tbl-cards tfoot, .tbl-cards tr, .tbl-cards td { display: block; width: 100%; }
	.tbl-cards tr { margin-bottom: 10px; padding: 12px 14px; border-radius: 18px; background: var(--glass-3); border: 1px solid var(--edge); }
	.tbl-cards tbody tr:hover td { background: none; }
	.tbl-cards td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border: 0; text-align: right; white-space: normal; }
	.tbl-cards td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; }
	.tbl-cards td.td-main { display: block; text-align: left; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
	.tbl-cards td.td-main::before, .tbl-cards td.td-actions::before { display: none; }
	.tbl-cards td.td-actions { justify-content: flex-end; padding-top: 8px; }
	.tbl-cards .need { max-width: 60vw; }
	.tbl-cards tfoot td { background: none; border-top: 0; }
	.table-wrap { overflow: visible; margin: 0; padding: 0; }
}
