/* ==========================================================================
   HiTechCloud portal — APP MODE (2026-11-17)
   Phones, tablets < 993px and touch tablets up to 1366px look and behave like a phone app.
   Desktop (mouse / trackpad) is untouched: every rule below sits under html.cm-appmode, which the inline script
   at the top of header.shared.tpl sets from
       (max-width: 992.98px), (pointer: coarse) and (max-width: 1366px)
   Pieces: compact top bar with safe areas · floating bottom tab bar (components/app-tabbar.tpl) · off-canvas drawer
   for the full menu (also on landscape tablets) · top-bar menus become bottom sheets on phones · order steps get a
   sticky "total · Tiếp tục" bar · 16px inputs (no zoom on focus) · 44px touch targets · press feedback ·
   chat bubble lifted above the tab bar.
   ĐỔI THƯƠNG HIỆU: colours come from portal.css tokens (--primary, --surface, --danger…); nothing is hard-coded here
   except the scrim and shadows.
   ========================================================================== */

.cm-tabbar, .cm-app-only { display: none; }

html.cm-appmode {
  --topbar-h: 56px;
  --app-safe-t: env(safe-area-inset-top, 0px);
  --app-safe-b: env(safe-area-inset-bottom, 0px);
  --app-safe-l: env(safe-area-inset-left, 0px);
  --app-safe-r: env(safe-area-inset-right, 0px);
  --app-tabbar-h: 64px;
  /* room the last line of a page needs to scroll clear of the tab bar (J2: inset-bottom + 96) */
  --app-bottom-space: calc(var(--app-safe-b) + 96px);
  --app-scrim: rgb(0 0 0 / 0.4);
  -webkit-text-size-adjust: 100%;
}
html.cm-appmode body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
html.cm-appmode .cm-app-only { display: block; }

/* ---------- Top bar ---------------------------------------------------- */
/* No backdrop-filter here: it would turn the bar into the containing block of the fixed bottom sheets below. */
html.cm-appmode .cm-topbar {
  height: calc(var(--topbar-h) + var(--app-safe-t));
  padding: var(--app-safe-t) max(12px, var(--app-safe-r)) 0 max(4px, var(--app-safe-l));
  gap: 4px;
}
html.cm-appmode .cm-topbar__right { gap: 2px; }
html.cm-appmode .cm-topbar .cm-iconbtn { width: 44px; height: 44px; }
html.cm-appmode .cm-sidebar__head { height: calc(var(--topbar-h) + var(--app-safe-t)); padding-top: var(--app-safe-t); }
html.cm-appmode .cm-topbar .cm-logo.cm-mobile-only { display: inline-flex !important; }
html.cm-appmode .cm-desktop-only { display: none !important; }
/* Hamburger icon (not the desktop collapse icons) on every app-mode width, landscape tablets included. */
html.cm-appmode [data-cm-sidebar-toggle] .cm-i-open,
html.cm-appmode [data-cm-sidebar-toggle] .cm-i-close { display: none !important; }
html.cm-appmode [data-cm-sidebar-toggle] .cm-i-menu { display: inline-block !important; }
/* Signed-in phones: language and light/dark move into the account sheet (components/account-menu.tpl, .cm-acct-menu__prefs). */
@media (max-width: 599.98px) {
  html.cm-appmode .cm-topbar:has(.cm-acct) .cm-lang,
  html.cm-appmode .cm-topbar:has(.cm-acct) > .cm-topbar__right > .cm-theme-btn { display: none !important; }
}

/* ---------- Drawer for the full menu (also >= 993px on touch tablets) ---- */
html.cm-appmode .cm-sidebar {
  width: min(288px, calc(100vw - 56px)) !important;
  transform: translateX(-100%);
  box-shadow: var(--elevation-modal);
  transition: transform .35s cubic-bezier(0.32, 0.72, 0, 1);
  padding-left: var(--app-safe-l);
}
html.cm-appmode body.sidenav-toggled .cm-sidebar { transform: none; transition-duration: .5s; }
html.cm-appmode .cm-overlay {
  display: block; position: fixed; inset: 0; z-index: 1035;
  background: var(--app-scrim); opacity: 0; pointer-events: none;
  transition: opacity .35s cubic-bezier(0.32, 0.72, 0, 1);
}
html.cm-appmode body.sidenav-toggled .cm-overlay { opacity: 1; pointer-events: auto; transition-duration: .5s; }
html.cm-appmode .cm-main,
html.cm-appmode body.sidenav-toggled .cm-main { margin-left: 0 !important; }
/* Undo the desktop icon-rail look that portal.css applies to body.sidenav-toggled from 993px. */
html.cm-appmode body.sidenav-toggled .cm-nav-link__text,
html.cm-appmode body.sidenav-toggled .cm-nav-count,
html.cm-appmode body.sidenav-toggled .cm-logo,
html.cm-appmode body.sidenav-toggled .cm-nav-label .cm-chevron,
html.cm-appmode body.sidenav-toggled .cm-nav-label__count { opacity: 1; }
html.cm-appmode body.sidenav-toggled .cm-nav-dot,
html.cm-appmode body.sidenav-toggled .cm-rail-mark { opacity: 0; }
html.cm-appmode body.sidenav-toggled .cm-nav-label { color: var(--muted); pointer-events: auto; }
html.cm-appmode body.sidenav-toggled .cm-nav-label .cm-nav-dash { display: none; }
html.cm-appmode .cm-sidebar .cm-nav-link,
html.cm-appmode .cm-sidebar .cm-nav-label { min-height: 44px; }

/* ---------- Page ------------------------------------------------------- */
html.cm-appmode .cm-main { padding-bottom: var(--app-bottom-space); }
html.cm-appmode .cm-content { padding-left: max(16px, var(--app-safe-l)); padding-right: max(16px, var(--app-safe-r)); }
html.cm-appmode .cm-footer { padding-left: max(16px, var(--app-safe-l)); padding-right: max(16px, var(--app-safe-r)); }
/* Root-of-tab title: large, left aligned (J3). Record pages keep their smaller title. */
html.cm-appmode .cm-page-head h1 { font-size: 28px; line-height: 34px; letter-spacing: -0.01em; }
html.cm-appmode .cm-page-head .cm-title--record { font-size: 20px; line-height: 26px; letter-spacing: 0; }
html.cm-appmode .cm-page-head__desc { font-size: 15px; }

/* Inputs at 16px: mobile browsers zoom the page on focus below that. */
html.cm-appmode input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
html.cm-appmode select,
html.cm-appmode textarea,
html.cm-appmode .form-control,
html.cm-appmode .select2-container .select2-selection,
html.cm-appmode .selectize-input { font-size: 16px !important; }
html.cm-appmode .form-control:not(textarea):not([multiple]),
html.cm-appmode select:not([multiple]) { min-height: 44px; }

/* Touch targets (J4): 44px. */
html.cm-appmode .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
html.cm-appmode .btn.btn-block { display: flex; }
html.cm-appmode .btn-sm { min-height: 40px; }
html.cm-appmode .dropdown-item { min-height: 44px; display: flex; align-items: center; gap: 8px; }
html.cm-appmode .cm-crumbs a { display: inline-flex; align-items: center; min-height: 44px; }

/* Press feedback instead of hover (J7). */
html.cm-appmode .btn,
html.cm-appmode .cm-tabbar__item,
html.cm-appmode .cm-stat,
html.cm-appmode .cm-quicknav a,
html.cm-appmode .cm-linkgrid a,
html.cm-appmode .cm-iconbtn,
html.cm-appmode .cm-acct__btn { transition: transform .12s ease-out, background-color .12s ease-out; }
html.cm-appmode .btn:active,
html.cm-appmode .cm-stat:active,
html.cm-appmode .cm-quicknav a:active,
html.cm-appmode .cm-linkgrid a:active,
html.cm-appmode .cm-iconbtn:active,
html.cm-appmode .cm-acct__btn:active { transform: scale(0.97); }
@media (hover: none) {
  html.cm-appmode .cm-iconbtn:hover:not(:active) { background: transparent; }
}

/* ---------- Bottom tab bar (J2, float) ---------------------------------- */
html.cm-appmode .cm-tabbar {
  display: flex; align-items: center; justify-content: space-between;
  position: fixed; z-index: 1020;
  left: max(16px, var(--app-safe-l)); right: max(16px, var(--app-safe-r));
  bottom: calc(var(--app-safe-b) + 8px);
  max-width: 560px; height: var(--app-tabbar-h); margin: 0 auto; padding: 0 8px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(1.6); backdrop-filter: blur(20px) saturate(1.6);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 6%, transparent), 0 10px 30px -10px rgb(11 23 48 / 0.28);
}
html.cm-appmode .cm-tabbar__item {
  position: relative; flex: 1 1 0; min-width: 0; height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 9999px; padding: 0 4px;
  color: var(--muted) !important; text-decoration: none !important;
}
html.cm-appmode .cm-tabbar__item .cm-i { width: 24px; height: 24px; }
html.cm-appmode .cm-tabbar__icon { position: relative; display: inline-flex; }
html.cm-appmode .cm-tabbar__label {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; line-height: 13px; font-weight: 500;
}
html.cm-appmode .cm-tabbar__item.is-active { color: var(--primary) !important; }
html.cm-appmode .cm-tabbar__item.is-active .cm-tabbar__label { font-weight: 600; }
html.cm-appmode .cm-tabbar__item:active { transform: scale(0.94); }
html.cm-appmode .cm-tabbar__item:focus { outline: none; }
html.cm-appmode .cm-tabbar__item:focus-visible { box-shadow: inset 0 0 0 2px var(--ring-focus); }
html.cm-appmode .cm-tabbar__badge {
  position: absolute; top: -4px; left: calc(100% - 8px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9999px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--surface);
}
/* 360px phones: five two-word labels ("Tổng quan") need every pixel. */
@media (max-width: 379.98px) {
  html.cm-appmode .cm-tabbar { left: max(12px, var(--app-safe-l)); right: max(12px, var(--app-safe-r)); padding: 0 4px; }
  html.cm-appmode .cm-tabbar__item { padding: 0 1px; }
  html.cm-appmode .cm-tabbar__item.is-active .cm-tabbar__label { font-weight: 500; }
}
/* Task pages own the bottom edge (J2): order steps with a summary + "Tiếp tục" (both order pages). Below 993px only:
   from there the summary is a sticky side column and the tab bar has room. */
@media (max-width: 992.98px) {
  html.cm-appmode body:has(#cart-wrapper a.cartSummaryContinue) .cm-tabbar { display: none; }
}

/* ---------- Top-bar menus as bottom sheets on phones (J6) ---------------- */
@media (max-width: 767.98px) {
  html.cm-appmode body .cm-app .cm-topbar .dropdown-menu,
  html.cm-appmode body .cm-app .cm-topbar .cm-acct-menu.dropdown-menu {
    position: fixed !important; inset: auto 0 0 0 !important; top: auto !important;
    width: auto !important; max-width: none; max-height: 85dvh; margin: 0 !important;
    overflow-y: auto; overscroll-behavior: contain;
    padding-top: 20px; padding-bottom: calc(8px + var(--app-safe-b));
    border: 0; border-radius: 24px 24px 0 0;
    box-shadow: 0 -10px 30px -10px rgb(11 23 48 / 0.25);
    transform: none !important; transform-origin: bottom center; z-index: 1050;
  }
  html.cm-appmode body .cm-app .cm-topbar .dropdown-menu::before {
    content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 5px; margin-left: -18px;
    border-radius: 9999px; background: var(--border-strong);
  }
  html.cm-appmode body .cm-app .cm-topbar .dropdown-menu.show { animation: cm-sheet-in .32s cubic-bezier(0.32, 0.72, 0, 1); }
  html.cm-appmode body .cm-app .cm-topbar .dropdown.show::after {
    content: ""; position: fixed; inset: 0; z-index: 1045; background: var(--app-scrim);
  }
  html.cm-appmode .cm-acct-menu__item { min-height: 48px; font-size: 15px; }
  html.cm-appmode .cm-acct-menu__stat-value { font-size: 17px; }
}
@keyframes cm-sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) {
  html.cm-appmode body .cm-app .cm-topbar .dropdown-menu.show { animation: none; }
  html.cm-appmode .cm-sidebar, html.cm-appmode .cm-overlay { transition-duration: .01s !important; }
}

/* Top-bar touch targets (J4): avatar and language buttons were 36px tall. */
html.cm-appmode .cm-acct__btn { height: 44px; min-width: 44px; justify-content: center; }
html.cm-appmode .cm-lang__btn { height: 44px; }
/* Shared bell (hc-bell.js): its size comes from --hcb-size; 36px on desktop, 44px touch target here. */
html.cm-appmode .cm-bell { --hcb-size: 44px; }
html.cm-appmode .cm-bell:not([data-hc-bell-ready]) { width: 44px; height: 44px; }
/* Account menu rows: 44px on every app-mode width (tablet popovers kept the 34px desktop rows). */
html.cm-appmode .cm-acct-menu__item { min-height: 44px; }
/* Names wrap, never cut (J4): the account sheet head and the dashboard quick-nav groups. */
html.cm-appmode .cm-acct-menu__head { flex-direction: column; align-items: flex-start; }
html.cm-appmode .cm-acct-menu__name { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; font-size: 16px; font-weight: 600; }
html.cm-appmode .cm-quicknav__name { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }

/* Account sheet: light/dark + language rows, only where the top bar dropped them (< 600px). */
html.cm-appmode .cm-acct-menu__prefs { display: none !important; }
@media (max-width: 599.98px) { html.cm-appmode .cm-acct-menu__prefs { display: grid !important; } }
html.cm-appmode .cm-acct-menu__prefs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 4px; padding: 6px; border-top: 1px solid var(--border); }
html.cm-appmode .cm-acct-menu__prefs .cm-acct-menu__item { border: 0; background: transparent; cursor: pointer; text-align: left; }
html.cm-appmode .cm-acct-menu__prefs .cm-acct-menu__item.is-current { color: var(--primary-strong) !important; font-weight: 600; }
html.cm-appmode .cm-acct-menu__prefs .cm-acct-menu__item.is-current .cm-i { color: var(--primary-strong); }

/* ---------- Order flow: sticky "total · Tiếp tục" bar (J5) on phones / portrait tablets ----
   Both order pages put the order summary in #cartSummary (re-rendered by AJAX) with a.cartSummaryContinue:
   cart_cloudmanager (.cmo-summary__total) and cart_2019wizard (.summary-section). CSS only: the bar background is a
   fixed ::after of #cartSummary, the total sits on its left, the button on its right. */
@media (max-width: 992.98px) {
  html.cm-appmode #cart-wrapper #cartSummary::after {
    content: ""; position: fixed; z-index: 1024; left: 0; right: 0; bottom: 0;
    height: calc(76px + var(--app-safe-b));
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px -16px rgb(11 23 48 / 0.25);
  }
  html.cm-appmode #cart-wrapper .cmo-summary__foot { margin: 0; padding: 0; border: 0; }
  html.cm-appmode #cart-wrapper a.cartSummaryContinue {
    position: fixed; z-index: 1026; right: max(16px, var(--app-safe-r)); bottom: calc(12px + var(--app-safe-b));
    width: 52% !important; min-height: 52px; margin: 0;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border-radius: 16px; font-size: 16px; font-weight: 600; line-height: 20px; padding: 0 16px;
  }
  html.cm-appmode #cart-wrapper .cmo-summary__total,
  html.cm-appmode #cart-wrapper #cartSummary .summary-section {
    position: fixed; z-index: 1026; left: max(16px, var(--app-safe-l)); bottom: calc(12px + var(--app-safe-b));
    width: calc(48% - 28px); height: 52px; margin: 0 !important; padding: 0; border: 0; background: none;
    display: flex; flex-direction: column; align-items: flex-start !important; justify-content: center; gap: 0;
  }
  html.cm-appmode #cart-wrapper .cmo-summary__total-label,
  html.cm-appmode #cart-wrapper #cartSummary .summary-section > strong { font-size: 12px; line-height: 16px; color: var(--muted); font-weight: 500; text-transform: none !important; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  html.cm-appmode #cart-wrapper #cartSummary .summary-section > strong small { font-size: inherit; }
  html.cm-appmode #cart-wrapper .cmo-summary__total-value,
  html.cm-appmode #cart-wrapper #cartSummary .summary-section > .h1 {
    max-width: 100%; margin: 0 !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 18px; line-height: 24px; font-weight: 600; font-variant-numeric: tabular-nums;
  }
  /* the summary card's last lines must scroll clear of the bar */
  html.cm-appmode #cart-wrapper { padding-bottom: 24px; }
}

/* ---------- Order pages (2019 wizard / categories_list) on phones ---------------------- */
@media (max-width: 767.98px) {
  /* Page head: title, description, then the currency picker on its own line (it was squeezed beside the title). */
  html.cm-appmode .orderpage .section-account-header { flex-direction: column !important; gap: 12px; margin-bottom: 16px !important; }
  html.cm-appmode .orderpage .section-account-header h1 { margin: 0 0 8px !important; font-size: 24px; line-height: 30px; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
  html.cm-appmode .orderpage .section-account-header h4 { margin: 0 !important; font-size: 15px; line-height: 22px; font-weight: 400; color: var(--muted); }
  html.cm-appmode .orderpage .section-account-header > div:last-child { justify-content: flex-start !important; margin: 0 !important; }
  html.cm-appmode .orderpage #currform { flex-wrap: nowrap; gap: 12px; }
  html.cm-appmode .orderpage #currform > span { margin: 0 !important; white-space: nowrap; color: var(--muted); }
  html.cm-appmode .orderpage #currform select { width: auto; min-width: 96px; }
  /* Sibling categories: one horizontally scrolling chip row instead of a 1,000px stack before the plans. */
  html.cm-appmode .orderpage-categories_list > .row {
    flex-wrap: nowrap; overflow-x: auto; gap: 8px; margin: 0 -24px; padding: 0 24px 4px; /* 16px page + 8px #cart-wrapper.px-2 */
    scroll-padding-inline: 24px;
    scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  html.cm-appmode .orderpage-categories_list > .row::-webkit-scrollbar { display: none; }
  html.cm-appmode .orderpage-categories_list > .row > [class*="col-"] { flex: 0 0 auto; width: auto; max-width: none; padding: 0; scroll-snap-align: start; }
  html.cm-appmode .orderpage-categories_list .cart-category {
    display: inline-flex; align-items: center; min-height: 44px; margin: 0 !important; padding: 0 16px !important;
    border-radius: 9999px !important; white-space: nowrap; box-shadow: none !important;
  }
  html.cm-appmode .orderpage-categories_list .cart-category .h3 { font-size: 15px; line-height: 20px; font-weight: 500; }
  html.cm-appmode .orderpage-categories_list .cart-category.selected { background: var(--primary) !important; border-color: var(--primary) !important; }
  html.cm-appmode .orderpage-categories_list .cart-category.selected .h3 { color: var(--primary-foreground) !important; }
}

/* ---------- Chat bubble (Chatwoot): icon-only, above the tab bar / sticky bar ---- */
html.cm-appmode .woot-widget-bubble.woot-elements--right {
  bottom: calc(var(--app-safe-b) + 84px) !important; right: max(16px, var(--app-safe-r)) !important;
}
html.cm-appmode .woot-widget-bubble.woot-widget--expanded {
  width: 56px !important; height: 56px !important; min-width: 0 !important; padding: 0 !important;
  border-radius: 9999px !important; justify-content: center;
}
html.cm-appmode .woot-widget-bubble.woot-widget--expanded #woot-widget--expanded__text { display: none !important; }
/* Out of the way while the drawer or a sheet is open. */
html.cm-appmode body.sidenav-toggled .woot-widget-bubble,
html.cm-appmode body:has(.cm-topbar .dropdown.show) .woot-widget-bubble { opacity: 0; pointer-events: none; }

/* ---------- Installed app (standalone): no browser chrome around the page ---- */
html.cm-appmode.cm-standalone body { -webkit-user-select: none; user-select: none; }
html.cm-appmode.cm-standalone input, html.cm-appmode.cm-standalone textarea,
html.cm-appmode.cm-standalone [contenteditable], html.cm-appmode.cm-standalone .cm-content p,
html.cm-appmode.cm-standalone .cm-content td, html.cm-appmode.cm-standalone .cm-content dd,
html.cm-appmode.cm-standalone .cm-num { -webkit-user-select: text; user-select: text; }
