/* ============================================================
   Shell of the v2 thin client, rendered by the server (light DOM): app bar (App button,
   shortcuts of the pinned apps, user box and account popover), page head, page aside
   (aside-host.js), login card. Ported from the v1 SPA (engine/ui/src/engine.css): same
   classes, so the server renders the v1 markup. No inline styles anywhere (CSP): the
   layout of the rx-app-shell slots uses .x-appbar / .x-appbar-actions.
   Tokens come from ./wc/theme.css.
   ============================================================ */

/* the shell fills the viewport and scrolls inside its canvas (like v1) */
html:has(#rx-app > rx-app-shell), body:has(#rx-app > rx-app-shell) { height: 100%; overflow: hidden; }
/* 100dvh: on iOS Safari 100vh includes the area under the browser toolbars */
#rx-app > rx-app-shell { display: block; height: 100vh; height: 100dvh; }
[data-node-id][hidden], [data-key][hidden] { display: none !important; }

/* ---------- boot and login logo mark (v1 .x-boot-mark: blue square with the R) ---------- */
.x-boot { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; background: var(--rx-canvas); }
.x-boot-card { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--rx-ink-2); }
.x-boot-mark { width: 44px; height: 44px; flex: none; border-radius: 11px; background: var(--rx-blue, #1447FF); color: #fff; display: grid; place-items: center; font-family: var(--rx-ff-display); font-weight: 700; font-size: 20px; line-height: 1; letter-spacing: -.03em; box-shadow: var(--rx-sh-2); user-select: none; }
.x-boot-error { max-width: 560px; padding: 0 16px; }

/* ---------- regions of the shell (server markup: rx-app-shell slots) ---------- */
/* App switcher: rx-popover around the App button (the launcher is its panel) */
.x-switcher { flex: none; display: inline-flex; align-items: center; }
/* breadcrumbs region in the topbar slot */
.x-crumbs { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 12px; overflow: hidden; }
.x-crumbs > rx-breadcrumbs { min-width: 0; flex: 1 1 auto; }
/* canvas content: banner above the main region */
.x-canvas { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 100%; }
.x-banner { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.x-banner:empty { display: none; }
.x-main { flex: 1 1 auto; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
/* a page with a component that fills its container ([data-rx-fill]): the regions down to the
   view grow to the height of the canvas */
.x-canvas > .x-work:has([data-rx-fill]) { flex: 1 1 auto; }
.x-work:has([data-rx-fill]) > .x-main { align-self: stretch; }
.x-main > .x-view:has([data-rx-fill]) { flex: 1 1 auto; }
.x-view > :has([data-rx-fill]) { flex: 1 1 auto; }

/* ---------- object list, modal body ---------- */
.x-list-card { background: var(--rx-surface); border: 1px solid var(--rx-line); border-radius: var(--rx-r-lg); overflow: hidden; }
.x-list-card rx-table { display: block; }
.x-modal-body { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.x-modal-body > rx-spinner { display: flex; justify-content: center; padding: 24px; }
.x-modal-body rx-alert[hidden], .x-modal-body [data-rx-form-alert][hidden] { display: none; }

/* ---------- app bar ---------- */
.x-appbar { display: flex; align-items: center; gap: 6px; min-width: 0; align-self: stretch; }
.x-appbar-actions { display: flex; align-items: center; gap: 5px; }
.x-launcher-btn { display: flex; align-items: center; gap: 8px; padding: 6px 11px 6px 9px; border-radius: var(--rx-r-md); background: rgba(255,255,255,.09); color: #fff; font: inherit; font-size: 12.5px; font-weight: 500; border: none; cursor: pointer; flex: none; transition: background .14s; }
.x-launcher-btn:hover { background: rgba(255,255,255,.17); }
.x-launcher-btn.is-active { background: var(--rx-blue); }.x-launcher-btn.is-open { background: rgba(255,255,255,.22); }
/* pinned apps in the app bar (like horizon-crm) */
.x-pins { display: flex; align-items: center; gap: 2px; margin-left: 10px; padding-left: 10px; position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; align-self: stretch; }
/* thin divider between the App button and the shortcuts */
.x-pins::before { content: ""; position: absolute; left: 0; top: 50%; height: 18px; margin-top: -9px; width: 1px; background: rgba(255,255,255,.14); }
.x-pins:empty { display: none; }
/* shortcuts (pinned apps): light text links with a small monochrome icon, unlike the filled App
   button; the current app: white text, bright blue icon, translucent blue background */
.x-pin-chip { position: relative; display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; color: #8C939E; font: inherit; font-size: 12px; font-weight: 400; letter-spacing: .005em; white-space: nowrap; background: none; border: 0; border-radius: var(--rx-r-md); cursor: pointer; transition: color .14s, background .14s; }
.x-pin-chip:hover { color: #E4E7EB; }
.x-pin-ico { display: grid; place-items: center; flex: none; color: currentColor; opacity: .8; }
/* rx-icon has the ink colour of the components: in the shortcuts it follows the text (the current one: blue) */
.x-pin-ico rx-icon { color: inherit; display: inline-grid; }
.x-pin-chip.is-active { color: #fff; font-weight: 500; background: rgba(79,163,255,.16); }
.x-pin-chip.is-active:hover { background: rgba(79,163,255,.22); }
.x-pin-chip.is-active .x-pin-ico { opacity: 1; color: #4FA3FF; }
.x-pins-more { padding: 6px 9px; border-radius: var(--rx-r-md); color: #B5BAC2; font-family: var(--rx-ff-mono); font-size: 11.5px; font-weight: 500; background: none; border: none; cursor: pointer; flex: none; }
.x-pins-more:hover { background: rgba(255,255,255,.1); color: #fff; }
@media (max-width: 720px) { .x-pin-label { display: none; } .x-pin-chip { padding: 0 6px; } .x-launcher-btn span { display: none; } }
.x-launcher-btn svg { display: block; }
/* bar icons (rx-icon follows the text colour): white on the App button and on Esci, like the v1 inline svg */
.x-launcher-btn rx-icon, .x-bar-logout rx-icon, .x-bar-imp-end rx-icon { color: inherit; display: inline-grid; flex: none; }
.x-launcher-btn, .x-launcher-btn:hover, .x-bar-logout, .x-bar-logout:hover { color: #fff; }
.x-bar-btn rx-icon { color: inherit; display: inline-grid; }
.x-bar-btn { width: 30px; height: 30px; border-radius: var(--rx-r-md); color: var(--rx-bar-txt); display: grid; place-items: center; background: none; border: none; cursor: pointer; transition: background .14s, color .14s; }
.x-bar-btn:hover { background: var(--rx-bar-2); color: #fff; }
.x-bar-avatar { width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--rx-ink); display: grid; place-items: center; font-size: 10.5px; font-weight: 600; margin-left: 3px; text-transform: uppercase; }
.x-side-version { font-family: var(--rx-ff-mono); font-size: 10.5px; color: var(--rx-ink-3); display: flex; justify-content: space-between; gap: 8px; }
.x-side-footer { display: flex; flex-direction: column; gap: 8px; }
.x-pins [hidden] { display: none !important; }
.x-ico { display: inline-grid; }

/* ---------- page head ---------- */
.x-view { display: flex; flex-direction: column; gap: 16px; min-width: 0; animation: x-fade-in .18s ease; }
/* opacity only: a transform animation would make the view the containing
   block of position:fixed descendants (rx-modal overlays inside x-flow) */
@keyframes x-fade-in { from { opacity: 0; } to { opacity: 1; } }
.x-page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.x-page-head .x-titles { flex: 1; min-width: 0; }
.x-page-title { font-size: 25px; line-height: 1.1; letter-spacing: -.03em; margin: 4px 0 0; }
.x-page-sub { font-size: 12.5px; color: var(--rx-ink-2); margin-top: 5px; max-width: 70ch; }
.x-page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- page aside (aside-host.js; rx-table filterPanelMode "page") ----------
   [page content | aside]: the aside is a column as tall as the canvas viewport, sticky in
   the canvas (the scroll container of rx-app-shell) and bleeding over its paddings, from
   just below the breadcrumbs bar to the bottom; it pushes the content to the left. The
   height and paddings come from the host (--x-aside-h, --x-aside-pt/pr/pb, measured on
   the canvas); the fallbacks match the shell (52px bar + 46px topbar, 22px padding). */
.x-aside-layout { --x-aside-w: 320px; --x-aside-gap: 20px; display: flex; align-items: flex-start; min-width: 0; }
.x-aside-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.x-aside { flex: none; align-self: flex-start; width: 0; height: 0; margin: 0; overflow: hidden; visibility: hidden; display: flex; flex-direction: column; background: var(--rx-surface); border-left: 0 solid var(--rx-line); transition: width .18s ease, margin-left .18s ease, visibility 0s linear .18s; }
.x-aside-layout[data-aside-open] > .x-aside {
  /* sticky offsets count from inside the scroller's padding: -pt puts the column at its top edge */
  position: sticky; top: calc(-1 * var(--x-aside-pt, 22px)); visibility: visible; width: var(--x-aside-w);
  height: var(--x-aside-h, calc(100dvh - 98px));
  margin: calc(-1 * var(--x-aside-pt, 22px)) calc(-1 * var(--x-aside-pr, 22px)) calc(-1 * var(--x-aside-pb, 22px)) var(--x-aside-gap);
  border-left-width: 1px;
  transition: width .18s ease, margin-left .18s ease;
}
/* fixed width (border excluded, box-sizing border-box): no reflow of the panel during the width transition */
.x-aside > * { flex: 1 1 auto; min-height: 0; width: calc(var(--x-aside-w) - 1px); }
@media (prefers-reduced-motion: reduce) { .x-aside, .x-aside-layout[data-aside-open] > .x-aside { transition: none; } }

/* ---------- SSO login ---------- */
.x-login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--rx-canvas); }
.x-login-card { width: min(380px, calc(100vw - 32px)); background: var(--rx-surface); border: 1px solid var(--rx-line); border-radius: var(--rx-r-lg); box-shadow: var(--rx-sh-2); padding: 22px 22px 20px; display: flex; flex-direction: column; gap: 14px; animation: x-fade-in .18s ease; }
.x-login-head { display: flex; align-items: center; gap: 12px; }
.x-login-titles { min-width: 0; }
.x-login-title { font-size: 22px; line-height: 1.1; letter-spacing: -.03em; margin: 3px 0 0; }
.x-login-sub { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 12.5px; color: var(--rx-ink-2); }
.x-login-form { display: flex; flex-direction: column; gap: 12px; }
.x-login-alert[hidden] { display: none; }

/* ---------- user (app bar) ---------- */
.x-bar-user { display: flex; align-items: center; gap: 7px; min-width: 0; padding-left: 4px; }
.x-bar-user-name { color: #fff; font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 18ch; }
.x-bar-logout { display: flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: var(--rx-r-md); background: rgba(255,255,255,.09); color: #fff; font: inherit; font-size: 12px; font-weight: 500; border: none; cursor: pointer; transition: background .14s; }
.x-bar-logout:hover { background: rgba(255,255,255,.17); }
/* account popover trigger: avatar + name (+ impersonation badge) */
.x-bar-user-btn { display: flex; align-items: center; gap: 7px; min-width: 0; padding: 3px 8px 3px 3px; border: 1px solid transparent; border-radius: 999px; background: transparent; color: #fff; font: inherit; cursor: pointer; transition: background .14s; }
.x-bar-user-btn:hover, rx-popover[open] .x-bar-user-btn { background: rgba(255,255,255,.12); }
.x-bar-user-btn .x-bar-avatar { margin-left: 0; }
.x-bar-user-btn.is-impersonating { border-color: #F2B544; background: rgba(242,181,68,.16); }
.x-bar-user-btn.is-impersonating .x-bar-avatar { background: #F2B544; }
.x-imp-ico { display: inline-grid; color: #F2B544; }
.x-imp-badge { padding: 1px 7px; border-radius: 999px; background: #F2B544; color: #3D2600; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; }
.x-bar-imp-end { display: flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: var(--rx-r-md); background: #F2B544; color: #3D2600; font: inherit; font-size: 12px; font-weight: 600; border: none; cursor: pointer; white-space: nowrap; }
.x-bar-imp-end:hover { background: #F7C766; }
/* account popover content */
.x-user-card { display: flex; flex-direction: column; gap: 10px; width: 280px; max-width: 100%; color: var(--rx-ink); }
.x-user-head { display: flex; align-items: center; gap: 11px; min-width: 0; }
.x-user-ids { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.x-user-display { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.x-user-username { font-family: var(--rx-ff-mono); font-size: 11.5px; color: var(--rx-ink-2); }
.x-user-email { font-size: 12px; color: var(--rx-ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.x-user-imp { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border-radius: var(--rx-r-md); background: #FDF3DD; color: #6B4200; font-size: 12px; font-weight: 500; }
.x-user-roles-label { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--rx-ink-3); }
.x-user-roles { display: flex; flex-wrap: wrap; gap: 5px; margin-top: -4px; }
.x-user-none { font-size: 12px; color: var(--rx-ink-3); }
.x-user-actions { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--rx-line); padding-top: 8px; }
.x-user-action { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 8px; border: none; border-radius: var(--rx-r-md); background: transparent; color: var(--rx-ink); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.x-user-action:hover { background: var(--rx-surface-2, #F7F8F9); }
.x-user-action.is-warn { color: #8A5300; }
/* account dialogs */
.x-password-form { display: flex; flex-direction: column; gap: 12px; }
.x-password-form rx-alert[hidden], [data-view="impersonate"] rx-alert[hidden] { display: none; }
.x-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
[data-view="impersonate"] { display: flex; flex-direction: column; gap: 10px; }
.x-imp-list { display: flex; flex-direction: column; gap: 2px; max-height: 360px; overflow: auto; }
.x-imp-user { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: none; border-radius: var(--rx-r-md); background: transparent; font: inherit; text-align: left; cursor: pointer; color: var(--rx-ink); }
.x-imp-user:hover { background: var(--rx-blue-wash); }
.x-imp-user-ids { display: flex; flex-direction: column; min-width: 0; font-size: 12px; color: var(--rx-ink-2); }
.x-imp-user-ids b { font-size: 13px; color: var(--rx-ink); font-weight: 600; }
/* v2: server-rendered account markup uses rx-icon (mask, key, logout) instead of the v1 inline svg */
.x-imp-ico rx-icon, .x-user-imp rx-icon, .x-user-action rx-icon, .x-imp-user rx-icon { color: inherit; display: inline-grid; flex: none; }
.x-user-action.is-warn rx-icon, .x-user-imp rx-icon { color: #B26B00; }
/* v2: the impersonation picker is a remote rx-lookup (query lane, key shell.impersonate) */
[data-view="impersonate"] rx-lookup, .x-password-form rx-input { width: 100%; }
.x-imp-note { font-size: 12px; color: var(--rx-ink-2); margin: 0; }
@media (max-width: 720px) {
  .x-bar-user-btn .x-bar-user-name, .x-bar-imp-end { font-size: 0; gap: 0; }
  .x-bar-user-btn .x-bar-user-name { display: none; }
}

/* ---------- screen flows (server-rendered x-flow: engine/ui/src/components/x-flow.js + base.js styles) ---------- */
.x-flow { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.x-flow-head { display: flex; flex-direction: column; gap: 10px; }
.x-flow-title { margin: 0; font-family: var(--rx-ff-display, "Inter Tight", system-ui, sans-serif); font-size: 17px; font-weight: 600; letter-spacing: -.02em; }
.x-flow-body { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.x-flow-card { background: var(--rx-surface, #fff); border: 1px solid var(--rx-line, #E4E6EA); border-radius: var(--rx-r-lg, 7px); padding: 18px 20px; }
.x-flow-done { text-align: center; }
.x-flow rx-alert[hidden] { display: none; }
.x-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rx-line, #E4E6EA); }
.x-actions .x-spacer, .x-flow-actions .x-spacer { flex: 1; }
/* the buttons of a screen in a modal: at the bottom of the modal body (v1: the footer slot of rx-modal) */
.x-flow-actions.x-modal-actions { align-items: center; width: 100%; padding-top: 12px; border-top: 1px solid var(--rx-line, #E4E6EA); }
.x-stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.x-muted { color: var(--rx-ink-3, #8B919B); font-size: 12px; }
