/* ============ CÀI APP (PWA) - nạp trên mọi lượt mở trang CRM, kể cả trang đăng nhập ============
   Cỡ chữ: theo TYPOGRAPHY.md (token --fs-* khai báo trong app.css; file này nạp cả khi app.css chưa nạp
   nên khai báo lại giá trị dự phòng). */
:root {
	--crm-pwa-ink: #172b4d; --crm-pwa-muted: #5e6c84; --crm-pwa-primary: #0052cc; --crm-pwa-soft: #e8f0fe; --crm-pwa-border: #dfe1e6;
}

/* Nút cài app: thanh trên cùng (icon tròn) và trang đăng nhập (nút dài). Ẩn khi đang ở trong app. */
.crm-install-btn {
	-webkit-appearance: none; appearance: none; display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
	border: 1px solid var(--crm-pwa-border); border-radius: 50%; background: #fff; color: var(--crm-pwa-muted); cursor: pointer; margin-left: 4px;
}
.crm-install-btn:hover { background: var(--crm-pwa-soft); color: var(--crm-pwa-primary); }
.crm-install-btn[hidden], html.crm-standalone .crm-install-btn { display: none; }
.crm-login-install {
	display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 44px; margin-top: 10px;
	border: 1px solid var(--crm-pwa-border); border-radius: 4px; background: #fff !important; color: var(--crm-pwa-primary) !important;
	font-weight: 600; font-size: 14px !important; cursor: pointer;
}
.crm-login-install[hidden], html.crm-standalone .crm-login-install { display: none; }

/* ---- Bảng hướng dẫn cài app (dialog trượt lên từ đáy trên điện thoại, giữa màn trên máy tính) ---- */
html.crm-ins-open { overflow: hidden; }
.crm-ins {
	position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%; max-height: 92dvh; margin: 0; padding: 0;
	border: 0; border-radius: 20px 20px 0 0; background: #fff; color: var(--crm-pwa-ink);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; overflow-y: auto; box-sizing: border-box;
	padding-bottom: env(safe-area-inset-bottom);
}
.crm-ins[open] { animation: crm-ins-up .24s cubic-bezier(.2, .8, .2, 1); }
@keyframes crm-ins-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.crm-ins::backdrop { background: rgba(9, 30, 66, .55); }
.crm-ins-grab { width: 40px; height: 4px; margin: 8px auto 0; border-radius: 4px; background: #d4d4d8; }
.crm-ins-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 16px 10px; }
.crm-ins-app { width: 52px; height: 52px; border-radius: 14px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .06); }
.crm-ins-head h2 { margin: 2px 0; font-size: 18px; line-height: 24px; font-weight: 700; }
.crm-ins-head p { margin: 0; font-size: 13px; line-height: 18px; color: var(--crm-pwa-muted); }
.crm-ins-x { width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 999px; background: #f4f5f7; color: var(--crm-pwa-ink); cursor: pointer; }
.crm-ins-body { padding: 2px 16px 0; }
.crm-ins-env { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; padding: 8px 12px; border-radius: 10px; background: var(--crm-pwa-soft); color: var(--crm-pwa-primary); font-size: 13px; line-height: 18px; font-weight: 500; }
.crm-ins-env b { font-weight: 700; }
.crm-ins-env .crm-ico { flex: none; }
.crm-ins-note { margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; background: #fff4e5; color: #974f0c; font-size: 14px; line-height: 20px; font-weight: 500; }
.crm-ins-guide { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 14px; align-items: start; }
.crm-ins-dev { position: relative; width: 72px; height: 128px; margin-bottom: 22px; border-radius: 16px; background: #f4f5f7; box-shadow: inset 0 0 0 2px #d4d4d8; }
.crm-ins-dev.is-tablet { height: 96px; border-radius: 12px; }
.crm-ins-dev.is-desktop { height: 54px; border-radius: 6px; }
.crm-ins-bar { position: absolute; left: 6px; right: 6px; height: 12px; border-radius: 6px; background: #e4e4e7; }
.crm-ins-bar.is-top { top: 8px; }
.crm-ins-bar.is-bottom { bottom: 8px; }
.crm-ins-dev.is-desktop .crm-ins-bar.is-top { top: 6px; height: 9px; border-radius: 3px; }
.crm-ins-dev.is-desktop .crm-ins-bar.is-bottom, .crm-ins-dev.is-tablet .crm-ins-bar.is-bottom { display: none; }
.crm-ins-dev[data-spot="bottom"] .crm-ins-bar.is-top, .crm-ins-dev[data-spot="bottom-right"] .crm-ins-bar.is-top { opacity: .5; }
.crm-ins-dot {
	position: absolute; left: 50%; top: 14px; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
	background: var(--crm-pwa-primary); box-shadow: 0 0 0 4px rgba(0, 82, 204, .25); animation: crm-ins-pulse 1.4s ease-out infinite;
}
@keyframes crm-ins-pulse { 0% { box-shadow: 0 0 0 0 rgba(0, 82, 204, .45); } 100% { box-shadow: 0 0 0 10px rgba(0, 82, 204, 0); } }
.crm-ins-dev[data-spot="bottom"] .crm-ins-dot { left: 50%; top: calc(100% - 14px); }
.crm-ins-dev[data-spot="bottom-right"] .crm-ins-dot { left: calc(100% - 14px); top: calc(100% - 14px); }
.crm-ins-dev[data-spot="top-right"] .crm-ins-dot { left: calc(100% - 14px); top: 14px; }
.crm-ins-dev[data-spot="address"] .crm-ins-dot { left: calc(100% - 14px); top: 10.5px; }
.crm-ins-dev[data-spot="toolbar"] .crm-ins-dot { left: calc(100% - 22px); top: 10.5px; }
.crm-ins-dev-k { position: absolute; left: -4px; right: -4px; top: calc(100% + 6px); text-align: center; font-size: 11px; line-height: 14px; font-weight: 600; color: var(--crm-pwa-primary); }
.crm-ins-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.crm-ins-steps li { display: grid; grid-template-columns: 22px 40px minmax(0, 1fr); gap: 10px; align-items: center; }
.crm-ins-n { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 999px; background: var(--crm-pwa-ink); color: #fff; font-size: 12px; font-weight: 700; line-height: 1; }
.crm-ins-key { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; background: #fff; color: var(--crm-pwa-ink); box-shadow: inset 0 0 0 1.5px var(--crm-pwa-border), 0 2px 0 var(--crm-pwa-border); }
.crm-ins-steps li:first-child .crm-ins-key { color: var(--crm-pwa-primary); box-shadow: inset 0 0 0 2px var(--crm-pwa-primary), 0 0 0 4px var(--crm-pwa-soft); }
.crm-ins-steps b { display: block; font-size: 15px; line-height: 20px; font-weight: 700; }
.crm-ins-steps small { display: block; margin-top: 2px; font-size: 13px; line-height: 18px; color: var(--crm-pwa-muted); }
.crm-ins-alt { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: #f4f5f7; font-size: 13px; line-height: 18px; color: #42526e; }
.crm-ins-copy {
	display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px; margin-top: 14px;
	border: 1px solid var(--crm-pwa-primary); border-radius: 8px; background: #fff; color: var(--crm-pwa-primary); font-size: 14px; font-weight: 600; cursor: pointer;
}
.crm-ins-copy.is-on { background: var(--crm-pwa-ink); color: #fff; border-color: var(--crm-pwa-ink); }
.crm-ins-foot { display: grid; gap: 6px; margin-top: 16px; padding: 12px 16px 14px; border-top: 1px solid #f1f2f4; }
.crm-ins-pick { display: grid; gap: 6px; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--crm-pwa-muted); }
.crm-ins-pick select { height: 44px; padding: 0 12px; border: 1px solid var(--crm-pwa-border); border-radius: 8px; background: #fff; color: var(--crm-pwa-ink); font-size: 14px; font-weight: 500; }
.crm-ins-done { justify-self: center; min-height: 40px; padding: 0 12px; border: 0; background: none; color: var(--crm-pwa-muted); font-size: 13px; font-weight: 500; text-decoration: underline; cursor: pointer; }
@media (min-width: 640px) {
	.crm-ins { inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: 480px; max-height: 88vh; border-radius: 16px; padding-bottom: 0; }
	.crm-ins[open] { animation: none; }
	.crm-ins-grab { display: none; }
}

/* ---- Thông báo nhỏ ---- */
.crm-toast {
	position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 10000; transform: translate(-50%, 0);
	max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px; background: var(--crm-pwa-ink); color: #fff;
	font-size: 13px; line-height: 18px; font-weight: 500; box-shadow: 0 6px 20px rgba(9, 30, 66, .25); transition: opacity .4s ease, transform .4s ease;
}
.crm-toast.is-out { opacity: 0; transform: translate(-50%, 8px); }

/* ---- Kéo xuống để tải lại (chỉ trong app đã cài) ---- */
.crm-ptr {
	position: fixed; left: 50%; top: 0; z-index: 10000; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
	transform: translate(-50%, -56px); border-radius: 999px; background: #fff; color: var(--crm-pwa-muted);
	font-size: 13px; font-weight: 600; box-shadow: 0 4px 16px rgba(9, 30, 66, .2); opacity: 0; pointer-events: none;
}
.crm-ptr.is-on { opacity: 1; transition: opacity .1s ease; }
.crm-ptr.is-go { color: var(--crm-pwa-primary); }
.crm-ptr-ico { display: grid; place-items: center; width: 18px; height: 18px; transition: transform .2s ease; }
.crm-ptr.is-go .crm-ptr-ico { transform: rotate(180deg); }
.crm-ptr.is-busy { transition: transform .2s ease, opacity .2s ease; }
.crm-ptr.is-busy .crm-ptr-ico { animation: crm-ptr-spin .8s linear infinite; }
@keyframes crm-ptr-spin { to { transform: rotate(360deg); } }

/* ---- Trang đích "Cài app" (/crm/?crm_app=install) ---- */
.crm-app-land {
	min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; margin: 0; padding: 16px;
	padding-bottom: calc(16px + env(safe-area-inset-bottom)); background: #f4f5f7; color: var(--crm-pwa-ink);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; box-sizing: border-box;
}
.crm-app-land-card { width: 100%; max-width: 420px; padding: 28px 20px; border-radius: 12px; background: #fff; box-shadow: 0 2px 12px rgba(9, 30, 66, .15); text-align: center; box-sizing: border-box; }
.crm-app-land-ico { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .06); }
.crm-app-land-kicker { margin: 14px 0 4px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--crm-pwa-muted); }
.crm-app-land h1 { margin: 0 0 8px; font-size: 22px; line-height: 28px; }
.crm-app-land-sub { margin: 0 0 16px; font-size: 14px; line-height: 20px; color: var(--crm-pwa-muted); }
.crm-app-land-why { list-style: none; margin: 0 0 20px; padding: 0; text-align: left; display: grid; gap: 8px; font-size: 14px; line-height: 20px; }
.crm-app-land-why li { position: relative; padding-left: 24px; }
.crm-app-land-why li::before { content: "✓"; position: absolute; left: 0; top: 0; color: #006644; font-weight: 700; }
.crm-app-land-btn {
	display: flex; align-items: center; justify-content: center; width: 100%; min-height: 50px; border: 0; border-radius: 8px;
	background: var(--crm-pwa-primary); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
}
.crm-app-land-btn[hidden] { display: none; }
.crm-app-land.is-ready .crm-app-land-btn { box-shadow: 0 0 0 4px var(--crm-pwa-soft); }
.crm-app-land-hint { margin: 10px 0 0; font-size: 12px; line-height: 16px; color: var(--crm-pwa-muted); }
.crm-app-land-done, .crm-app-land-in { display: none; padding: 14px; border-radius: 10px; background: #e3fcef; color: #006644; }
.crm-app-land-done b, .crm-app-land-in b { font-size: 16px; }
.crm-app-land-done p, .crm-app-land-in p { margin: 6px 0 0; font-size: 14px; }
.crm-app-land.is-installed .crm-app-land-done { display: block; }
.crm-app-land.is-installed .crm-app-land-do { display: none; }
html.crm-standalone .crm-app-land-in { display: block; }
html.crm-standalone .crm-app-land-do, html.crm-standalone .crm-app-land-why, html.crm-standalone .crm-app-land-skip { display: none; }
.crm-app-land-ghost { display: inline-block; margin-top: 4px; padding: 10px 18px; border-radius: 8px; background: var(--crm-pwa-primary); color: #fff; text-decoration: none; font-weight: 600; }
.crm-app-land-skip { margin: 16px 0 0; font-size: 13px; }
.crm-app-land-skip a { color: var(--crm-pwa-muted); }

/* ---- Trang Admin "Cài app" ---- */
.crm-pwa-cols { display: flex; flex-direction: column; gap: 16px; }
.crm-pwa-col { min-width: 0; }
.crm-pwa-qr { max-width: 200px; }
.crm-pwa-qr svg { width: 100%; height: auto; border: 1px solid var(--crm-pwa-border); border-radius: 8px; }
.crm-pwa-prev { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.crm-pwa-prev img.is-ios { border-radius: 14px; }
.crm-pwa-prev img.is-and { border-radius: 50%; }
.crm-pwa-checks { margin: 0; padding: 0; list-style: none; }
.crm-pwa-checks li { position: relative; padding: 4px 0 4px 22px; }
.crm-pwa-checks li::before { position: absolute; left: 0; top: 4px; font-weight: 700; }
.crm-pwa-checks .is-ok::before { content: "✓"; color: #006644; }
.crm-pwa-checks .is-warn::before { content: "!"; color: #974f0c; }
.crm-pwa-checks .is-bad::before { content: "✕"; color: #bf2600; }
@media (min-width: 900px) {
	.crm-pwa-cols { flex-direction: row; align-items: flex-start; }
	.crm-pwa-col { flex: 1 1 0; }
}

/* ---- Trong app đã cài: không có thanh địa chỉ, chừa vùng an toàn ---- */
html.crm-standalone .crm-topbar { padding-top: calc(8px + env(safe-area-inset-top)); }
