/* ============================================================
   LEDGER LAYOUT — admin app shell (sidebar + topbar + page frame)
   Ported 1:1 from design/minimart-dashboard.html; token-only, no
   raw hues, no arbitrary values. Owns the chrome + page-grid
   classes the primitives (components.css) don't cover.
   ============================================================ */

/* ---------- app grid ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.16s ease-out;
}

/* ---------- sidebar ---------- */
.side {
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.brand {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
}
/* An uploaded logo (Superadmin -> Theme, or the shop's own) stands in for the
   WHOLE lockup — mark and wordmark — so it is sized by height and left free to
   be as wide as it needs, up to the sidebar. `contain` so nothing is cropped. */
/* Beside the wordmark, when "show the name" is on: a fixed square that keeps
   the lockup from shifting as logos of different widths load. */
.brand .mk-img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
}
.brand .brand-logo {
  height: 30px;
  max-width: 100%;
  object-fit: contain;
  object-position: left center;
}
.brand .mk {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13.5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), var(--sh-1);
}
.brand b {
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -0.015em;
  display: inline-block;
  transition: opacity 0.1s ease;
}
.brand b em {
  font-style: normal;
  color: var(--accent);
}
.side-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  scrollbar-width: none;
}
.side-scroll::-webkit-scrollbar {
  display: none;
}
.side-scroll > * {
  flex: none;
}
.sec {
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--content-3);
  padding: 16px 9px 6px;
  white-space: nowrap;
  overflow: hidden;
}
.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--content-2);
  text-decoration: none;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.1s, color 0.1s;
}
.nav .ico {
  color: var(--content-3);
  transition: color 0.1s;
}
.nav:hover {
  background: var(--surface-sunken);
  color: var(--content);
}
.nav:hover .ico {
  color: var(--content-2);
}
.nav.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav.active .ico {
  color: var(--accent);
}
.nav .lbl {
  display: inline-block;
  transition: opacity 0.1s ease;
}
.nav .ct {
  margin-inline-start: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--content-3);
}
.nav .ct.warn {
  color: var(--warning);
  font-weight: 600;
  background: var(--warning-soft);
  padding: 1px 6px;
  border-radius: var(--r-pill);
}
.nav .kbd {
  margin-inline-start: auto;
}
.sysline {
  flex: none;
  padding: 11px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--content-2);
  background: var(--surface);
  white-space: nowrap;
  overflow: hidden;
}
.sysline .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}
.sysline .lbl {
  display: inline-block;
  transition: opacity 0.1s ease;
}
.sysline .v {
  margin-inline-start: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--content-3);
}

/* ---------- collapsed sidebar (html.collapsed) ---------- */
html.collapsed .app {
  grid-template-columns: 60px 1fr;
}
html.collapsed .brand {
  gap: 0;
  padding: 0;
  justify-content: center;
}
html.collapsed .brand b {
  opacity: 0;
  width: 0;
}
html.collapsed .side-scroll {
  padding: 8px 8px 12px;
}
html.collapsed .sec {
  height: 1px;
  padding: 0;
  margin: 9px 9px;
  background: var(--border);
  font-size: 0;
}
html.collapsed .nav {
  gap: 0;
  justify-content: center;
  padding: 9px 0;
}
html.collapsed .nav .lbl {
  opacity: 0;
  width: 0;
}
html.collapsed .nav .ct,
html.collapsed .nav .kbd {
  display: none;
}
html.collapsed .sysline {
  gap: 0;
  padding: 11px 0;
  justify-content: center;
}
html.collapsed .sysline .lbl,
html.collapsed .sysline .v {
  opacity: 0;
  width: 0;
  display: inline-block;
  overflow: hidden;
}

/* ---------- topbar ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
/* Scoped to the <header> element so it can't leak into other `.top` rows —
   notably KpiCard's inner `.kpi .top` label/sparkline row, which otherwise
   inherited position:sticky + height and floated over the real top bar. */
header.top {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 26px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.crumb {
  font-size: 12.5px;
  color: var(--content-3);
  white-space: nowrap;
}
.crumb b {
  color: var(--content);
  font-weight: 600;
}
.search {
  width: 340px;
  min-width: 0;
  margin-inline-start: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  height: 34px;
  color: var(--content-3);
  font-family: var(--font-ui);
  font-size: 12.5px;
  cursor: text;
  transition: border-color 0.12s, background 0.12s;
}
.search:hover {
  border-color: var(--border-strong);
  background: var(--surface);
}
.search .txt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search .kbd {
  margin-inline-start: auto;
}
.sp {
  flex: 1;
}
/* Prominent register launcher in the top bar (→ /pos, F1). */
.pos-launch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.pos-launch:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.pos-launch .kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
  color: inherit;
}
/* The base .kbd rule (components.css) fills this pill with --surface, which
   is fine over .pos-launch's own light rest-state background — but on hover
   the parent flips to a solid --accent fill and this badge's `color:
   inherit` follows it to --on-accent (white), leaving white text stranded on
   the still-light --surface pill underneath. Same fix as .btn-primary/
   .btn-danger's kbd: a translucent pill derived from the fill instead of a
   detached light box. */
.pos-launch:hover .kbd {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.34);
  color: rgba(255, 255, 255, 0.92);
}
.tdiv {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}
/* Branch + language chips group. On desktop the wrapper is transparent to the
   header flex (contents); on phones it hides and the `⋯` overflow menu shows. */
.chips-inline {
  display: contents;
}
.chips-overflow {
  display: none;
}
/* Drawer scrim — only rendered as an overlay inside the phone media query. */
.scrim {
  display: none;
}
/* Top-bar select chips (branch switcher + language). Shared look: 36px tall,
   soft border + shadow, lift on hover, muted caret. */
.chip-branch,
.chip-lang {
  display: flex;
  align-items: center;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--sh-1);
  cursor: pointer;
  white-space: nowrap;
  color: var(--content);
  font-family: var(--font-ui);
  transition: border-color 0.13s, box-shadow 0.13s, background 0.13s;
}
.chip-branch:hover,
.chip-lang:hover {
  border-color: var(--border-strong);
  box-shadow: var(--sh-2);
}
.chip-branch .caret,
.chip-lang .caret {
  color: var(--content-3);
  transition: color 0.13s;
}
.chip-branch:hover .caret,
.chip-lang:hover .caret {
  color: var(--content-2);
}

/* both chips: icon tile + label/value stack + caret */
.chip-branch,
.chip-lang {
  gap: 8px;
  padding-inline: 8px 9px;
}
.chip-branch .tile,
.chip-lang .tile {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
}
.chip-branch .tile .ico,
.chip-lang .tile .ico {
  color: inherit;
}
.chip-branch .bt,
.chip-lang .bt {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.chip-branch small,
.chip-lang small {
  font-size: 8.5px;
  font-weight: 650;
  letter-spacing: 0.11em;
  color: var(--content-3);
  text-transform: uppercase;
  text-align: start;
}
.chip-branch .bn,
.chip-lang .bn {
  font-size: 12.5px;
  font-weight: 600;
  max-width: 168px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lang-opt small {
  font-size: 11px;
  color: var(--content-3);
}
.iconbtn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--content-2);
  cursor: pointer;
  background: none;
  position: relative;
}
.iconbtn:hover {
  background: var(--surface-sunken);
  color: var(--content);
}
.iconbtn .bdg {
  position: absolute;
  top: 7px;
  inset-inline-end: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  border: 1.5px solid var(--surface);
}
.avatar {
  width: 31px;
  height: 31px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--info));
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  border: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* ---------- page frame ---------- */
.page {
  padding: 22px 26px 32px;
  max-width: 1340px;
  width: 100%;
  margin: 0 auto;
}
.phead {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin: 2px 0 20px;
}
.phead h1 {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.022em;
}
.phead .meta {
  color: var(--content-2);
  font-size: 12.5px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
.phead .meta .sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border-strong);
}
.phead .actions {
  margin-inline-start: auto;
  display: flex;
  gap: 9px;
  align-items: center;
}
.live {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
  color: var(--success);
  background: var(--success-soft);
  border-radius: var(--r-pill);
  padding: 2px 8px;
}
.live i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* ---------- page grids (T1 KPI row, ops strip, column layout) ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.ops {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.cols {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.cols .span2 {
  grid-column: span 2;
}

@media (max-width: 1100px) {
  .kpis,
  .ops {
    grid-template-columns: repeat(2, 1fr);
  }
  /* With the rail eating 264px, two 220px-min tracks can overrun the ~452px
     of content left at 768px — let the 1fr tracks size themselves instead. */
  .kpi {
    min-width: 0;
  }
  .cols {
    grid-template-columns: 1fr;
  }
  .cols .span2 {
    grid-column: span 1;
  }

  /* Tablet portrait keeps the full sidebar rail, so the top bar has less room
     than on desktop — condense it here (not just on phones): icon-only search,
     drop the breadcrumb, and fold the branch/language chips into the ⋯ menu.
     Otherwise they overflow past the squeezed content. */
  .search {
    width: auto;
    flex: none;
  }
  .search .txt,
  .search .kbd {
    display: none;
  }
  .crumb {
    display: none;
  }
  .chips-inline {
    display: none;
  }
  .chips-overflow {
    display: inline-block;
  }
  /* Icon-only POS pill when the top bar is condensed. */
  .pos-launch {
    padding: 0;
    width: 34px;
    justify-content: center;
    gap: 0;
  }
  .pos-launch .lbl,
  .pos-launch .kbd {
    display: none;
  }
}
/* ---------- phone: off-canvas drawer sidebar + condensed top bar ---------- */
@media (max-width: 767px) {
  /* Single column; the sidebar leaves the grid and becomes a fixed drawer.
     Also neutralise a carried-over desktop `.collapsed` state. */
  .app,
  html.collapsed .app {
    grid-template-columns: 1fr;
  }
  .side {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: 264px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  /* Shadow only while open — on the base .side it bled onto the viewport edge
     from the off-screen (translateX(-100%)) drawer. */
  html.nav-open .side {
    transform: translateX(0);
    box-shadow: var(--sh-pop);
  }
  /* RTL: the drawer is anchored to the right edge, so it slides in from there. */
  [dir='rtl'] .side {
    transform: translateX(100%);
  }
  html.nav-open[dir='rtl'] .side {
    transform: translateX(0);
  }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  html.nav-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }
  html.nav-open,
  html.nav-open body {
    overflow: hidden;
  }

  /* KPI + ops cards: one per row on phones. The .kpi min-width (220px) forced
     two 220px tracks past the viewport and clipped the right column. */
  .kpis,
  .ops {
    grid-template-columns: 1fr;
  }
  .kpi {
    min-width: 0;
  }
}

/* ---------- auth (login / reset) ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
}
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-brand .mk-img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: contain;
  flex-shrink: 0;
}
.auth-brand .brand-logo {
  height: 40px;
  max-width: 220px;
  object-fit: contain;
}
.auth-brand .mk {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), var(--sh-1);
}
.auth-brand b {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.015em;
}
.auth-brand b em {
  font-style: normal;
  color: var(--accent);
}
.auth-head {
  margin-bottom: 18px;
}
.auth-head h1 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.auth-head p {
  font-size: 12.5px;
  color: var(--content-2);
  margin-top: 4px;
}
.auth-foot {
  margin-top: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--content-3);
}

/* The "Install app" offer (Superadmin → Theme → PWA install prompt). Fixed to
   the foot of the viewport so it never displaces the till or the sidebar, and
   above the shell's own chrome but below modals. */
.install-prompt {
  position: fixed;
  inset-inline: 12px;
  bottom: 12px;
  z-index: 40;
  margin-inline: auto;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: var(--sh-2);
}
.install-prompt b {
  display: block;
  font-size: 13.5px;
}
.install-prompt span {
  display: block;
  font-size: 12.5px;
}

/* Superadmin → Theme → brand colour. Groups separated by a rule, matching
   the reference app's own panel. */
.theme-colour-group {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.theme-colour-group:first-of-type {
  margin-top: 22px;
}
.theme-swatch {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border), var(--sh-1);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.theme-swatch:hover {
  transform: scale(1.1);
}
.theme-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* The chosen one keeps a ring rather than a tick: a check mark in an unknown
   ink is illegible on half of these colours. */
.theme-swatch.is-active {
  box-shadow: 0 0 0 2px var(--accent), var(--sh-1);
}
