/* ============================================================
   App shell — sidebar, topbar, layout
   ============================================================ */

/* Side-collapsed mode (driven by the sidebar's toggle button). The body
   class is set in src/shell.jsx; the grid column shrinks to the
   --nav-w-collapsed width and labels are hidden by the component. */
body.side-collapsed .app[data-nav="side"],
body.side-collapsed .app:not([data-nav]) {
  grid-template-columns: var(--nav-w-collapsed) 1fr;
}
.side--collapsed .side__group-label { display: none; }
.side--collapsed .side__item .label,
.side--collapsed .side__item .badge,
.side--collapsed .side__item .count { display: none; }
.side--collapsed .side__item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "side topbar"
    "side main";
  height: 100vh;
  min-height: 720px;
  overflow: hidden;
}

.app[data-nav="collapsed"] { grid-template-columns: var(--nav-w-collapsed) 1fr; }
.app[data-nav="top"] {
  grid-template-columns: 1fr;
  grid-template-rows: var(--topbar-h) var(--subbar-h) 1fr;
  grid-template-areas: "topbar" "subnav" "main";
}
.app[data-nav="top"] .side { display: none; }
.app[data-nav="top"] .subnav { display: flex; }

.app[data-nav="hybrid"] {
  grid-template-columns: var(--nav-w-collapsed) 1fr;
  grid-template-rows: var(--topbar-h) var(--subbar-h) 1fr;
  grid-template-areas:
    "side topbar"
    "side subnav"
    "side main";
}
.app[data-nav="hybrid"] .subnav { display: flex; }

.subnav { display: none; }

/* ----------------- Sidebar ----------------- */
.side {
  grid-area: side;
  background: var(--side-bg);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--side-border);
  overflow: hidden;
}
.side__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--side-border);
  min-height: var(--topbar-h);
}
.side__brand .logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--p-400), var(--p-600) 60%, #6a39c9);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), inset 0 1px 0 rgba(255,255,255,.2);
  flex-shrink: 0;
}
.side__brand .name {
  font-size: var(--fs-md);
  font-weight: 650;
  color: #fff;
  letter-spacing: -0.01em;
}
.side__brand .name small {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: var(--side-text-dim);
  letter-spacing: 0.02em;
  margin-top: 1px;
}

.side__brand-switch {
  margin: 10px 10px 8px;
  padding: 8px 10px;
  background: var(--side-bg-2);
  border: 1px solid var(--side-border);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--side-text);
  font-size: var(--fs-sm);
  transition: background .12s;
}
.side__brand-switch:hover { background: #1b243e; }
.side__brand-switch .brand-dot {
  width: 16px; height: 16px; border-radius: 4px;
  background: linear-gradient(135deg, #e6a82c, #c48a14);
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.2);
}
.side__brand-switch .brand-info { flex: 1; min-width: 0; }
.side__brand-switch .brand-info .b-name { font-weight: 600; color: #fff; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side__brand-switch .brand-info .b-sub { font-size: 10.5px; color: var(--side-text-dim); }

.side__group {
  margin-top: 6px;
  padding: 0 10px;
}
.side__group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--side-text-dim);
  padding: 10px 10px 6px;
}
.side__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-md);
  color: var(--side-text);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .1s var(--ease), color .1s;
  user-select: none;
  position: relative;
}
.side__item:hover { background: var(--side-bg-2); color: #fff; }
.side__item.active {
  background: var(--side-active-bg);
  color: var(--side-active-text);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
}
.side__item.active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 2.5px;
  background: var(--p-400);
  border-radius: 0 2px 2px 0;
}
.side__item .icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.side__item .label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side__item .badge {
  font-size: 10.5px;
  font-weight: 600;
  background: var(--p-500);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  line-height: 1.4;
}
.side__item .count {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--side-text-dim);
  background: #1b243e;
  padding: 1px 6px;
  border-radius: 999px;
  line-height: 1.4;
}

.side__spacer { flex: 1; }

.side__footer {
  padding: 10px;
  border-top: 1px solid var(--side-border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.side__footer .user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--r-md);
  transition: background .1s;
}
.side__footer .user:hover { background: var(--side-bg-2); }
.side__footer .u-name { font-size: var(--fs-sm); color: #fff; font-weight: 500; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side__footer .u-role { font-size: 10.5px; color: var(--side-text-dim); line-height: 1.2; }

/* ----------------- Topbar ----------------- */
.topbar {
  grid-area: topbar;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
}
.topbar__title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.topbar__breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-tertiary);
  font-size: var(--fs-md);
}
.topbar__breadcrumb .sep { color: var(--n-200); }
.topbar__breadcrumb .current { color: var(--text-primary); font-weight: 500; }

.topbar__search {
  position: relative;
  width: 340px;
  max-width: 32vw;
}
.topbar__search .input {
  padding-left: 32px;
  background: var(--n-50);
  border-color: transparent;
  font-size: var(--fs-sm);
}
.topbar__search .input:focus { background: var(--n-0); }
.topbar__search .kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-tertiary);
  background: var(--n-0);
  border: 1px solid var(--border-default);
  padding: 1px 5px;
  border-radius: 4px;
}
.topbar__search svg.ic {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* ----------------- Sub nav (horizontal tabs row below topbar) ----------------- */
.subnav {
  grid-area: subnav;
  background: var(--n-0);
  border-bottom: 1px solid var(--border-default);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
}
.subnav__item {
  font-size: var(--fs-md);
  font-weight: 500;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.subnav__item:hover { background: var(--n-75); color: var(--text-primary); }
.subnav__item.active { background: var(--p-50); color: var(--p-700); }
.subnav__item .icon { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ----------------- Main ----------------- */
.main {
  grid-area: main;
  overflow: auto;
  background: var(--surface-canvas);
}

.page {
  padding: 18px 22px 40px;
  max-width: 1680px;
  margin: 0 auto;
}

.page__header {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 18px;
}
.page__title {
  font-size: var(--fs-2xl);
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  line-height: 1.15;
  white-space: nowrap;
}
.page__subtitle {
  font-size: var(--fs-md);
  color: var(--text-secondary);
  margin-top: 3px;
}
/* Phase F/F3: `white-space: nowrap` used to live on .page__subtitle globally, which
   overflowed the viewport on Host and report pages (their subtitles are long
   descriptive sentences). Scoped to the PayBO surface, whose subtitles are short —
   PayBO renders identically, Host wraps instead of overflowing. */
.page:not(.hrs-page):not([class*="host-"]) > .page__header .page__subtitle,
.page:not(.hrs-page):not([class*="host-"]) .page__subtitle {
  white-space: nowrap;
}
.section__title { white-space: nowrap; }
.kpi__label { white-space: nowrap; }
.kpi__value { white-space: nowrap; }
.page__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Section */
.section + .section { margin-top: 16px; }
.section__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-default);
}
.section__title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
}
.section__desc { font-size: var(--fs-sm); color: var(--text-secondary); }
.section__actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.section__body { padding: 14px; }

/* Grids */
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

/* Toolbar row above tables */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-default);
  background: var(--n-25);
  flex-wrap: wrap;
}
.toolbar .input, .toolbar .select { width: auto; }
.toolbar .filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
}
.toolbar .filter-chip:hover { background: var(--n-0); color: var(--text-primary); }
.toolbar .filter-chip.active {
  border-style: solid;
  background: var(--p-50);
  border-color: var(--p-200);
  color: var(--p-700);
}

/* Icon-only nav when collapsed */
.app[data-nav="collapsed"] .side__item .label,
.app[data-nav="collapsed"] .side__item .badge,
.app[data-nav="collapsed"] .side__item .count,
.app[data-nav="collapsed"] .side__group-label,
.app[data-nav="collapsed"] .side__brand .name,
.app[data-nav="collapsed"] .side__brand-switch .brand-info,
.app[data-nav="collapsed"] .side__footer .u-name,
.app[data-nav="collapsed"] .side__footer .u-role { display: none; }

.app[data-nav="collapsed"] .side__item { justify-content: center; padding: 8px; }
.app[data-nav="collapsed"] .side__brand { justify-content: center; padding: 12px 10px; }
.app[data-nav="collapsed"] .side__brand-switch { padding: 8px; justify-content: center; margin: 10px 8px; }
.app[data-nav="collapsed"] .side__brand-switch .brand-dot { width: 20px; height: 20px; }
.app[data-nav="collapsed"] .side__footer { justify-content: center; }

/* Hybrid: sidebar is icon-only */
.app[data-nav="hybrid"] .side__item .label,
.app[data-nav="hybrid"] .side__item .badge,
.app[data-nav="hybrid"] .side__item .count,
.app[data-nav="hybrid"] .side__group-label,
.app[data-nav="hybrid"] .side__brand .name,
.app[data-nav="hybrid"] .side__brand-switch .brand-info,
.app[data-nav="hybrid"] .side__footer .u-name,
.app[data-nav="hybrid"] .side__footer .u-role { display: none; }
.app[data-nav="hybrid"] .side__item { justify-content: center; padding: 8px; }
.app[data-nav="hybrid"] .side__brand { justify-content: center; padding: 12px 10px; }
.app[data-nav="hybrid"] .side__brand-switch { padding: 8px; justify-content: center; margin: 10px 8px; }
.app[data-nav="hybrid"] .side__footer { justify-content: center; }

/* Top-nav pattern */
.topnav-brand {
  display: flex; align-items: center; gap: 10px;
  padding-right: 16px;
  border-right: 1px solid var(--border-default);
  height: 100%;
}
.topnav-brand .logo { width: 26px; height: 26px; border-radius: 6px; background: linear-gradient(135deg, var(--p-400), var(--p-600) 60%, #6a39c9); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; }

/* Tweak panel — base styles. Extended look/previews live in tweaks-extras.css */
.tweaks {
  position: fixed;
  right: 16px;
  top: auto;
  bottom: 16px;
  max-height: calc(100vh - 32px);
  width: 300px;
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: 0 20px 40px -12px rgba(15,20,32,.28), 0 4px 12px -4px rgba(15,20,32,.12);
  z-index: 100;
  display: none;
  overflow: hidden;
  flex-direction: column;
}
.tweaks.visible { display: flex; }
.tweaks__head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--n-25);
  flex-shrink: 0;
}
.tweaks__title { font-weight: 600; font-size: var(--fs-md); }
.tweaks__body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex: 1;
}
.tweaks__label { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-tertiary); margin-bottom: 6px; }
.tweaks__options { display: flex; gap: 6px; flex-wrap: wrap; }
.tweaks__option {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-default);
  background: var(--n-0);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  text-align: center;
  transition: border-color .12s, background .12s, color .12s;
}
.tweaks__option:hover {
  border-color: var(--border-strong);
  background: var(--n-25);
}
.tweaks__option.active {
  border-color: var(--p-500);
  background: var(--p-50);
  color: var(--p-700);
}

/* Skeletons / placeholders */
.ph {
  background: linear-gradient(90deg, var(--n-75) 0%, var(--n-100) 50%, var(--n-75) 100%);
  background-size: 200% 100%;
  animation: ph 1.4s infinite linear;
  border-radius: 4px;
}
@keyframes ph { 0% { background-position: 100% 0 } 100% { background-position: -100% 0 } }

/* Drawer */
.drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 520px;
  background: var(--surface-panel);
  border-left: 1px solid var(--border-default);
  box-shadow: -20px 0 40px rgba(15,20,32,.08);
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.drawer__head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  gap: 10px;
}
.drawer__body { padding: 16px; overflow: auto; flex: 1; }

/* ── Sign-in gate ─────────────────────────────────────────────────────────
   A blocking overlay, not a banner. The app renders underneath but must not be
   readable through it: 69 empty screens behind a login box read as "the system
   has no data", which is the misreading this gate exists to prevent. Hence an
   opaque backdrop rather than a translucent scrim. */
.sb-gate {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--surface-app, #f4f6fa);
  overflow: auto;
}
.sb-gate__card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-panel, #fff);
  border: 1px solid var(--border-default);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 20, 32, .14);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sb-gate__brand { display: flex; gap: 12px; align-items: flex-start; }
.sb-gate__mark {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--p-500, #2a3fd0);
  color: #fff;
}
.sb-gate__title { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.sb-gate__sub {
  margin-top: 4px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.sb-gate__note {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-secondary);
  background: var(--surface-subtle, #f7f8fb);
  border: 1px solid var(--border-default);
  border-radius: 9px;
  padding: 11px 13px;
}
.sb-gate__fix { margin-top: 7px; color: var(--text-primary); }

/* Two-factor enrolment. The QR sits on white regardless of theme: a dark-mode
   inversion of a QR code is unreadable to about half of scanner apps, which
   read it as a light-on-dark code they were never given. */
.sb-gate__qr { display: grid; place-items: center; padding: 4px 0; }
.sb-gate__qrimg {
  width: 176px; height: 176px;
  background: #fff;
  padding: 10px;
  border: 1px solid var(--border-default);
  border-radius: 10px;
}
.sb-gate__qrfallback {
  font-size: 12.5px; line-height: 1.55;
  color: var(--text-secondary);
  background: var(--surface-subtle, #f7f8fb);
  border: 1px solid var(--border-default);
  border-radius: 9px;
  padding: 11px 13px;
  width: 100%;
}
.sb-gate__qrnote { margin-bottom: 7px; }
.sb-gate__qruri {
  display: block;
  font-size: 11px;
  word-break: break-all;
  color: var(--text-primary);
}
/* The shared secret, shown once. Monospace and letter-spaced because it is
   going to be typed by hand by whoever cannot scan, and a mistaken character
   here fails silently 30 seconds later with no clue which one it was. */
.sb-gate__secret {
  margin-top: 7px;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 13px;
  letter-spacing: .08em;
  word-break: break-all;
  color: var(--text-primary);
  background: var(--surface-panel, #fff);
  border: 1px solid var(--border-default);
  border-radius: 7px;
  padding: 8px 10px;
  user-select: all;
}
.sb-gate__form { display: flex; flex-direction: column; gap: 6px; }
.sb-gate__label {
  font-size: 11.5px;
  font-weight: 650;
  color: var(--text-secondary);
  margin-top: 6px;
}
.sb-gate__form .input { width: 100%; }
.sb-gate__submit { margin-top: 14px; width: 100%; justify-content: center; }
.sb-gate__err {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 12.5px; line-height: 1.5;
  color: var(--err-700, #a3001b);
  background: var(--err-50, #fdecec);
  border: 1px solid var(--err-100, #fbd1d1);
  border-radius: 9px;
  padding: 10px 12px;
}
.sb-gate__err svg { flex: none; margin-top: 2px; }
.sb-gate__signout { align-self: flex-start; }
.sb-gate__foot {
  display: flex; gap: 14px; flex-wrap: wrap;
  border-top: 1px solid var(--border-default);
  padding-top: 13px;
}
.sb-gate__link {
  background: none; border: 0; padding: 0;
  font-size: 12px;
  color: var(--p-700, #8a0b20);
  text-decoration: underline;
  cursor: pointer;
}
.sb-gate__diag {
  margin: 0;
  max-height: 190px;
  overflow: auto;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  background: var(--surface-subtle, #f7f8fb);
  border: 1px solid var(--border-default);
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--text-secondary);
}
@media (max-width: 520px) {
  .sb-gate { padding: 0; align-items: stretch; }
  .sb-gate__card { max-width: none; border: 0; border-radius: 0; box-shadow: none; padding: 22px 18px; }
}


/* ----------------- Impersonation bar -----------------
   Fixed, full width, above everything except the sign-in gate (9000). The
   colour is the one warning tone in the palette and is used nowhere else, so
   the strip cannot be mistaken for a normal banner.

   `position: fixed` plus a body offset rather than a sticky element in the
   layout: the app's shell already owns the top of the page, and pushing it
   down from inside would mean touching a shared file's layout rules. This
   sits over the top edge and the shell scrolls under it. */
.sb-imp {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 8500;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  font-size: 13px;
  line-height: 1.35;
  color: #3b2600;
  background: #ffca4a;
  border-bottom: 1px solid #d8a318;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .18);
}
.sb-imp__txt { flex: 1 1 auto; min-width: 0; }
.sb-imp__stop {
  flex: 0 0 auto;
  padding: 3px 12px;
  font: inherit;
  font-weight: 600;
  color: #3b2600;
  background: rgba(255, 255, 255, .75);
  border: 1px solid #b8871a;
  border-radius: 5px;
  cursor: pointer;
}
.sb-imp__stop:hover:not(:disabled) { background: #fff; }
.sb-imp__stop:disabled { opacity: .6; cursor: default; }

/* The bar overlays the top edge, so the app needs the same amount of room
   back. The flag is set and cleared by SbImpersonationBar's own effect —
   a body class rather than a wrapper element, because the shell owns the
   layout and pushing it down from inside would mean editing shared rules. */
body.has-imp-bar .app { padding-top: 34px; }

@media (max-width: 520px) {
  .sb-imp { flex-wrap: wrap; font-size: 12px; }
  .sb-imp__txt { flex: 1 1 100%; order: 2; }
  body.has-imp-bar .app { padding-top: 58px; }
}
