/* public/styles/portal-shell.css — THE FRAME, ONCE (queue item IT, R235).
   ═══════════════════════════════════════════════════════════════════════════
   Loaded by admin.html AND app.html, after components.css. It is the ONE
   definition of the shell: the top bar's ground, the rail, the person block,
   the nav rows and their counts, the collapse control, the phone drawer and the
   phone tab bar. Neither entry point styles any of these any more — CI-META-3e
   fails a rule in admin.html or styles/portal/*.css whose selector names the
   shell (the old `.sidebar` / `.nav-item` / `.portal-sidebar` /
   `.portal-nav-item` / `.pnav-*` / `.abn-*` / `.portal-bottom-tab*` hooks
   included), because two implementations of one frame drift, and they did.

   The spec is the approved v8 kit (kaf-mockups-v8/kit.css, lines 13-39):
   a navy top bar and a navy rail, the person first (avatar, name, role line),
   flat rows 40px / 14px / 500 / radius 10, active = white 10% and white text,
   counts right-aligned, no dividers, no group headers, collapse at the bottom.

   The markup keeps the class hooks the two routers and the specs read
   (`.nav-item`, `.portal-nav-item`, `#sidebar`, `.portal-sidebar`, …) beside
   the shared classes; the hooks carry NO style. This sheet reads only the
   shared `kaf-rail*` / `kaf-topbar` / `kaf-tabbar*` names.

   DENSITY is the only per-portal difference the design system allows, and it
   is one token: `--density`, added to a rail row's height. It is 0 on both
   portals today — the v8 mockups draw the admin's rail and the client's at the
   same 40px — so the token exists to say where the difference would go, not
   to make one.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --sh: 56px;             /* the top bar */
  --sw: 232px;            /* the rail */
  --sw-collapsed: 64px;   /* the rail, icons only */
  --density: 0px;         /* the one per-portal knob; see the header */
}

/* ── THE TOP BAR ─────────────────────────────────────────────────────────── */
.kaf-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--sh);
  padding: 0 var(--sp-5);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  background: var(--shell-chrome);
  border-bottom: 0;
  color: var(--on-dark);
}

/* ── THE BODY UNDER IT ───────────────────────────────────────────────────── */
.kaf-shell-body { display: flex; align-items: flex-start; padding-top: var(--sh); min-height: 100vh; }
.kaf-shell-main { flex: 1 1 auto; min-width: 0; }

/* ── THE RAIL ────────────────────────────────────────────────────────────── */
.kaf-rail {
  position: sticky; top: var(--sh); z-index: 100;
  flex: none;
  width: var(--sw);
  height: calc(100vh - var(--sh));
  display: flex; flex-direction: column;
  padding: var(--sp-4) var(--sp-3);
  background: var(--shell-rail);
  border: 0;
  overflow-x: hidden; overflow-y: auto;
  transition: width .25s cubic-bezier(.4, 0, .2, 1);
  font-family: var(--sans);
}

/* The person: avatar, name, role line. */
.kaf-rail-person {
  position: relative;
  display: flex; align-items: center; gap: var(--sp-3);
  min-width: 0;
  padding: var(--sp-2) var(--sp-2) var(--sp-5);
  color: var(--on-dark);
}
.kaf-rail-avatar {
  position: relative; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; overflow: hidden;
  border: 0;
  font-family: var(--sans); font-size: var(--type-small); font-weight: 600; line-height: 1; letter-spacing: .01em;
}
/* The person's tint is the shared ramp's (js/shared/avatar-ramp.js, keyed on
   who they are), so the same person wears the same colour in every list on
   both portals; until a portal has painted it, the kit's quiet on-dark disc. */
.kaf-rail-avatar:not([class*="avatar-ramp-"]) { background: var(--on-dark-14); color: var(--on-dark); }
.kaf-rail-avatar img { width: 100%; height: 100%; object-fit: cover; }
.kaf-rail-who { flex: 1; min-width: 0; }
.kaf-rail-name {
  display: block;
  font-size: var(--type-body); font-weight: 600; line-height: 1.2; color: var(--on-dark);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kaf-rail-role {
  display: block; margin-top: 2px;
  font-size: var(--t-meta); font-weight: 400; line-height: 1.3; color: var(--on-dark-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kaf-rail-role:empty { display: none; }
/* The small mark that stands in for the person when the rail is icons only. */
.kaf-rail-mark { display: none; font-size: var(--type-title); margin: 0 auto var(--sp-4); }

/* The rows. */
.kaf-rail-nav { display: flex; flex-direction: column; min-width: 0; }
.kaf-rail-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; height: calc(40px + var(--density)); min-height: 0;
  margin: 0; padding: 0 var(--sp-3);
  border: 0; border-radius: var(--r-control);
  background: transparent; color: var(--on-dark-66);
  font-family: var(--sans); font-size: var(--t-small); font-weight: 500; line-height: 1.2; letter-spacing: normal;
  text-align: left; text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: background-color .12s, color .12s;
}
@media (hover: hover) and (pointer: fine) { .kaf-rail-item:hover { background: var(--on-dark-06); color: var(--on-dark); } }
/* QUEUE ITEM IR — the page you are on gets the brand blue: a 3px rule on its
   leading edge and a blue icon. Blue = "you are here / press this", nothing else. */
.kaf-rail-item.active {
  background: linear-gradient(var(--accent-on-dark), var(--accent-on-dark)) left / 3px 100% no-repeat, var(--on-dark-10);
  color: var(--on-dark); font-weight: 500;
}
.kaf-rail-item.active .kaf-rail-icon { color: var(--accent-on-dark); }
.kaf-rail-item:focus-visible { outline: 2px solid var(--accent-on-dark); outline-offset: -2px; }
.kaf-rail-item[hidden] { display: none; }
.kaf-rail-icon, .kaf-tabbar-icon, .kaf-shell-icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  pointer-events: none;
}
.kaf-rail-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* THE COUNT, right-aligned, in the same slot on both portals. */
.kaf-rail-count {
  margin-left: auto; flex: none;
  min-width: 0; padding: 0; border: 0; background: none;
  font-family: var(--sans); font-size: var(--type-label); font-weight: 500; line-height: 1;
  color: var(--on-dark-50); font-variant-numeric: tabular-nums;
  position: relative;
}
.kaf-rail-item.active .kaf-rail-count { color: var(--on-dark-75); }
.kaf-rail-count--unread { color: var(--accent-on-dark); }
/* A dot is a count without a number: "something here needs you". */
.kaf-rail-count--dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-on-dark); }
button.kaf-rail-count { cursor: pointer; }
button.kaf-rail-count::after { content: ''; position: absolute; inset: -14px -10px; }
button.kaf-rail-count:focus-visible { outline: 2px solid var(--accent-on-dark); outline-offset: 3px; border-radius: 2px; }
.kaf-rail-count:empty:not(.kaf-rail-count--dot) { display: none; }

/* COLLAPSE, at the bottom. */
.kaf-rail-collapse {
  margin-top: auto; flex: none;
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  width: 100%; min-height: 40px; padding: var(--sp-2);
  border: 0; border-radius: var(--r-control); background: none;
  color: var(--on-dark-40); cursor: pointer;
  font-family: var(--sans); font-size: var(--type-small);
}
@media (hover: hover) and (pointer: fine) { .kaf-rail-collapse:hover { color: var(--on-dark-75); } }
.kaf-rail-collapse:focus-visible { outline: 2px solid var(--accent-on-dark); outline-offset: -2px; }
.kaf-rail-collapse .kaf-rail-icon { width: 16px; height: 16px; transition: transform .3s; }

/* Icons only (desktop), remembered per device by each portal's toggle. */
.kaf-rail.collapsed { width: var(--sw-collapsed); padding-left: var(--sp-2); padding-right: var(--sp-2); }
.kaf-rail.collapsed .kaf-rail-person,
.kaf-rail.collapsed .kaf-rail-label,
.kaf-rail.collapsed .kaf-rail-count { display: none; }
.kaf-rail.collapsed .kaf-rail-mark { display: block; }
.kaf-rail.collapsed .kaf-rail-item { justify-content: center; padding: 0; }
.kaf-rail.collapsed .kaf-rail-collapse .kaf-rail-icon { transform: rotate(180deg); }
/* The icons-only rail names each door on hover and on keyboard focus, drawn
   from the row's accessible name (js/shared/portal-shell.js keeps it in step
   with the translated label) — not a native `title`, which lags and sticks. */
.kaf-rail.collapsed { overflow: visible; }
.kaf-rail.collapsed .kaf-rail-item { position: relative; }
.kaf-rail.collapsed .kaf-rail-item::after
{
  /* TF3: drawn only once it has content, below, so the tip is described once */
  position: absolute; left: calc(100% + var(--sp-2)); top: 50%; transform: translateY(-50%); z-index: 300;
  padding: var(--sp-1) var(--sp-2); border-radius: var(--r-chip);
  background: var(--shell-chrome); color: var(--on-dark);
  font-size: var(--t-meta); font-weight: 500; white-space: nowrap; pointer-events: none;
  box-shadow: var(--elev-2);
} .kaf-rail.collapsed .kaf-rail-item:focus-visible::after { content: attr(aria-label); } @media (hover: hover) and (pointer: fine) { .kaf-rail.collapsed .kaf-rail-item:hover::after { content: attr(aria-label); } }

/* ── PHONE: THE RAIL IS A DRAWER ─────────────────────────────────────────── */
.kaf-rail-scrim { display: none; }
@media (max-width: 768px) {
  .kaf-topbar { padding: 0 var(--sp-4); }
  .kaf-rail,
  .kaf-rail.collapsed {
    position: fixed; top: var(--sh); left: 0; bottom: 0; z-index: 210;
    width: min(280px, 85vw); height: auto;
    padding: var(--sp-4) var(--sp-3);
    transform: translateX(-100%); visibility: hidden;
    transition: transform .3s cubic-bezier(.4, 0, .2, 1), visibility 0s linear .3s;
  }
  .kaf-rail.open, .kaf-rail.open-mobile {
    transform: none; visibility: visible; box-shadow: var(--elev-4);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1), visibility 0s;
  }
  .kaf-rail.collapsed .kaf-rail-person { display: flex; }
  .kaf-rail.collapsed .kaf-rail-label, .kaf-rail.collapsed .kaf-rail-count { display: revert; }
  .kaf-rail.collapsed .kaf-rail-mark { display: none; }
  .kaf-rail.collapsed .kaf-rail-item { justify-content: flex-start; padding: 0 var(--sp-3); }
  /* 44 is the floor under a finger; the drawer gives 48. */
  .kaf-rail-item { height: calc(48px + var(--density)); font-size: var(--t-body); }
  .kaf-rail-collapse { display: none; }
  .kaf-rail-scrim { position: fixed; inset: 0; z-index: 205; background: var(--scrim-a50); }
  .kaf-rail-scrim.open { display: block; }
}

/* ── PHONE: THE TAB BAR ──────────────────────────────────────────────────── */
.kaf-tabbar { display: none; }
@media (max-width: 768px) {
  .kaf-tabbar {
    display: flex; align-items: stretch;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding: 0 0 calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--paper);
    border-top: 1px solid var(--line);
    box-shadow: none;
  }
  .kaf-tabbar-strip { display: flex; flex: 1; align-items: stretch; height: auto; }
  /* The content clears the bar. */
  .kaf-shell-body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
}
.kaf-tabbar-item {
  position: relative;
  flex: 1 1 0; min-width: 0; min-height: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-1);
  padding: var(--sp-1) 2px 0;
  border: 0; background: none;
  color: var(--muted);
  font-family: var(--sans); font-size: var(--type-label); font-weight: 500; line-height: 1.1;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
/* QUEUE ITEM KP (A-07) — a word never breaks mid-letter: "Entrenamien / to" was
   `overflow-wrap: anywhere`. The tab bar's words are short on purpose (the
   Spanish Training tab says "Entrenar"), so a label that cannot fit is a label
   to shorten, not one to cut. */
/* QUEUE ITEM TF2 — and a label is ONE line. "Habits & Goals" wrapped between its
   words and lifted its icon above the other four; a tab says one short word
   ("Habits"), and the page keeps the long name. */
.kaf-tabbar-item > span { max-width: 100%; white-space: nowrap; overflow-wrap: normal; word-break: normal; hyphens: manual; text-align: center; }
/* QUEUE ITEM KX (F-20, F-21) — …and the longest word always fits its tab.
   "Calendario" is 5.2 em wide, wider than a 320 px phone's fifth at the
   Standard size and than a 390 px fifth at Largest, so the label is capped by
   its own tab's width (`cqi`) rather than allowed to run into its neighbour. */
.kaf-tabbar-item { container-type: inline-size; padding-left: 0; padding-right: 0; }
.kaf-tabbar-item > span { font-size: min(1em, calc((100cqi - 4px) / 5.5)); }
/* QUEUE ITEM TF2 — Spanish has longer one-word doors than "Calendario": "Documentos" is 6.06 em and
   "Facturación" 5.64, wider than a 390 px fifth (78), so they ran into the next tab. Measured, not guessed.
   The widest word also keeps 2 px of its tab clear each side ("Documents" is 5.46 em, not 5.2): two long
   labels side by side were 4 px apart and read as one phrase. English at 390 is unchanged (13 px). */
.kaf-tabbar-item > span:lang(es) { font-size: min(1em, calc((100cqi - 4px) / 6.2)); }
.kaf-tabbar-item.active { color: var(--primary); }
.kaf-tabbar-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: var(--r-chip); }
.kaf-tabbar-item svg { width: 20px; height: 20px; }
.kaf-tabbar-badge {
  position: absolute; top: 6px; right: calc(50% - 18px);
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary); display: none;
}
.kaf-tabbar-badge[data-count]:not([data-count="0"]) { display: block; }

/* ── COGNITIVE-SIMPLIFIED ────────────────────────────────────────────────── */
/* The larger touch floor, and no counts: a number beside a door is a second
   thing to read. The portal's rule for every other control, applied here once. */
body.cognitive-simplified .kaf-rail-item,
body.cognitive-simplified .kaf-tabbar-item { min-height: 56px; }
body.cognitive-simplified .kaf-rail-item { height: auto; }
body.cognitive-simplified .kaf-rail-count { display: none !important; }

/* ── PRINT ───────────────────────────────────────────────────────────────── */
@media print {
  .kaf-topbar, .kaf-rail, .kaf-tabbar, .kaf-rail-scrim { display: none !important; }
  .kaf-shell-body { padding: 0; }
}

/* A wrapper a portal gates as one (the client's AI Trainer door). */
.kaf-rail-slot { position: relative; display: block; }
/* QUEUE ITEM KJ (C-15) — a count is part of its row ("Schedule 3"), and it
   stays visible when the rail is collapsed: on the icon's corner. */
@media (min-width: 769px) {
  .kaf-rail.collapsed .kaf-rail-count:not([style*="none"]):not(:empty) {
    display: inline-flex; position: absolute; top: 2px; right: 2px; margin: 0;
  }
}

/* ── GATES ───────────────────────────────────────────────────────────────── */
/* `hidden` hides a door, whichever portal's scope decided it (applyTrainerScope
   on /admin, the feature and nutrition gates on /app). */
.kaf-rail-item[hidden], .kaf-tabbar-item[hidden], .kaf-rail-slot[hidden] { display: none !important; }
/* Queue item FR (R163) — Course is per-PERSON: closed by DEFAULT, so a boot
   that never reaches applyTrainerScope() leaves the door shut, not open. */
body:not([data-course-access="on"]) .kaf-rail-item[data-page="course"] { display: none; }

/* "Something needs you" on the person's avatar (an unpaid invoice today). A
   dot is information, not an affordance. */
.kaf-rail-dot {
  display: none; position: absolute; top: 6px; left: 42px; z-index: 2;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--red); border: 2px solid var(--shell-rail);
  pointer-events: none;
}
.kaf-rail-dot.is-active { display: block; }

/* ── MOTION ──────────────────────────────────────────────────────────────── */
/* WCAG 2.3.3: the rail's width and the drawer's slide are decoration, and a
   reader who asked the system for less motion gets the end state at once. */
@media (prefers-reduced-motion: reduce) {
  .kaf-rail, .kaf-rail-item, .kaf-rail-collapse .kaf-rail-icon, .kaf-rail.open, .kaf-rail.open-mobile { transition: none; }
}

/* ── QUEUE ITEM JZ — FOCUS YOU CAN SEE, ON BOTH PORTALS ───────────────────────
   F-19 / A-03: no `scroll-padding` existed anywhere, so Tab parked focus under
   the fixed top bar and the phone's tab bar; the skip link slid under the top
   bar; the top-bar rings were 1 px and low contrast. WCAG 2.4.11 (Focus Not
   Obscured), 2.4.7, 2.4.13 (2 px). One ring: 2 px solid, 2 px off the control —
   the focus blue on the canvas, white on the dark top bar and rail. */
html { scroll-padding-top: calc(var(--sh) + var(--sp-2)); }
@media (max-width: 768px) {
  html { scroll-padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px) + var(--sp-2)); }
}
:focus-visible { outline: 2px solid var(--primary-strong); outline-offset: 2px; }
.kaf-topbar :focus-visible,
.kaf-topbar .topbar-btn:focus-visible,
.kaf-rail .kaf-rail-item:focus-visible,
.kaf-rail :focus-visible { outline: 2px solid var(--on-dark); outline-offset: 2px; box-shadow: none; }

/* The skip link: invisible until focused, then a 44 px chip BELOW the top bar
   (it used to open at y = −7, under the bar, and push the page down). */
.kaf-skip-link {
  position: fixed; top: calc(var(--sh) + var(--sp-2)); left: var(--sp-3); z-index: 1400;
  min-height: 44px; padding: 0 var(--sp-4);
  display: inline-flex; align-items: center;
  border-radius: var(--r-pill);
  background: var(--shell-chrome); color: var(--on-dark);
  font: 600 var(--t-small)/1 var(--sans); text-decoration: none;
  transform: translateY(calc(-100% - var(--sh) - var(--sp-4)));
}
.kaf-skip-link:focus, .kaf-skip-link:focus-visible { transform: none; outline: 2px solid var(--on-dark); outline-offset: 2px; }

/* Every sheet's ✕ (js/shared/dialog.js names it and adds one where a sheet had
   none): 44 px, top right. */
.kaf-dialog-x {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.kaf-dialog-x--added, .kaf-dialog-x--float {
  border: 0; background: none; color: inherit; cursor: pointer;
  border-radius: var(--r-chip); font-size: var(--t-body);
}
.kaf-dialog-x--added { margin-left: auto; }
.kaf-dialog-x--float { position: absolute; top: var(--sp-2); right: var(--sp-2); z-index: 2; }
.kaf-shell-main:focus:not(:focus-visible), .kaf-shell-main[tabindex="-1"]:focus { outline: none; }

/* LKe — the rail's Find a client (a 44 outlined box), its fold-out doors' chevrons
   (lit while the panel shows), and the thin line before Course (admin-chrome; the rail is the shared shell, so its pieces live here, CI-META-3e). */
.kaf-rail-find { display: flex; align-items: center; gap: var(--s-8); flex: none; width: 100%; height: 44px; margin: 0 0 var(--s-8); padding: 0 var(--s-12);
  border: 1px solid var(--chrome-line); border-radius: var(--r-control); background: none; color: var(--on-chrome-muted); font: inherit; font-size: var(--t-small); text-align: left; cursor: pointer; }
.kaf-rail-item[aria-expanded="true"] { background: var(--on-chrome-hover); color: var(--on-dark); } @media (hover: hover) and (pointer: fine) { .kaf-rail-find:hover { background: var(--on-chrome-hover); color: var(--on-dark); } }
.kaf-rail-find .kaf-rail-icon, .kaf-rail-chev .kaf-rail-icon { width: 16px; height: 16px; stroke-width: 2; }
.kaf-rail-chev { display: flex; }
.kaf-rail-sep { border: 0; border-top: 1px solid var(--chrome-line); margin: var(--s-8) var(--s-12); }
.kaf-rail.collapsed .kaf-rail-find { justify-content: center; padding: 0; }
.kaf-rail.collapsed .kaf-rail-chev { display: none; }
