/* ═══════════════════════════════════════════════════════════════
   KREDITS — App Shell Styles
   Requires kredits-tokens.css to be loaded first.
   All shell elements are injected by kredits-shell.js;
   this file only styles them.
═══════════════════════════════════════════════════════════════ */

/* ── SIGNED-IN HINT ─────────────────────────────────────────────
   Each app page's <head> adds html.k-signed-in before first paint when this
   device was signed in last time; KreditsAuth.ready() removes it if the
   session turns out to be gone. Until then, keep the sign-in cards out of
   sight rather than flash them at a teacher who is signed in. */
html.k-signed-in #screen-auth,
html.k-signed-in #screen-signin { display: none !important; }

/* ── SHARED ICON-BUTTON ─────────────────────────────────────── */
.ks-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 150ms ease, color 150ms ease;
  padding: 0;
}
.ks-icon-btn:hover {
  background: var(--surface-neutral);
  color: var(--ink);
}
.ks-icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* ── TOP BAR ────────────────────────────────────────────────── */
#ks-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--ks-topbar-h);
  z-index: 300;
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-2);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

#ks-topbar-center {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ks-topbar-class {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

/* Avatar circle (right side → links to Settings) */
.ks-avatar {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
  transition: opacity 150ms ease;
}
.ks-avatar:hover {
  background: var(--accent-hover);
}
.ks-avatar::after { content: ""; position: absolute; inset: -4px; }   /* 44px hit area */
.ks-avatar:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.ks-avatar span {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--on-accent);
  letter-spacing: 0.04em;
  line-height: 1;
  user-select: none;
}


/* ── LEFT SIDEBAR ───────────────────────────────────────────── */
#ks-sidebar {
  position: fixed;
  top: var(--ks-topbar-h);
  left: 0;
  bottom: 0;
  width: var(--ks-sidebar-w);
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  /* transition added via .ks-transitions-ready (prevents flash on load) */
}

body.ks-transitions-ready #ks-sidebar {
  transition: width 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

#ks-sidebar.ks-collapsed {
  width: var(--ks-sidebar-cw);
}

/* Nav item list */
#ks-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Sidebar nav items */
.ks-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  text-decoration: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}
.ks-nav-item:hover {
  background: var(--surface-neutral);
  color: var(--ink);
}
.ks-nav-item.ks-active {
  background: var(--accent-tint);
  color: var(--accent);
  border-left-color: var(--accent);
}
.ks-nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


.ks-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: inherit;
}

.ks-nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  max-width: 200px;
  transition: opacity 180ms ease, max-width 250ms ease;
}

/* Collapsed: hide labels, centre icons */
#ks-sidebar.ks-collapsed .ks-nav-label {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
}

#ks-sidebar.ks-collapsed .ks-nav-item {
  justify-content: center;
  padding: 0;
  gap: 0;
  border-left-color: transparent;
  border-radius: var(--radius-sm);
}

/* Active state in collapsed mode: accent background without left border */
#ks-sidebar.ks-collapsed .ks-nav-item.ks-active {
  background: var(--accent-tint);
  color: var(--accent);
}

/* Section headings in the menu (My classes, Learning, In the lesson).
   Collapsed: a thin rule in place of the words. */
.ks-nav-section {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-3) 2px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
}
#ks-sidebar.ks-collapsed .ks-nav-section {
  padding: var(--space-2) var(--space-2) 0;
}
#ks-sidebar.ks-collapsed .ks-nav-section span {
  display: block;
  height: 1px;
  overflow: hidden;
  color: transparent;
  background: var(--border);
}

/* Pinned-bottom nav section (e.g. Settings) */
#ks-sidebar-nav-bottom {
  flex-shrink: 0;
  padding: var(--space-2);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Collapse toggle button at the bottom of the sidebar */
#ks-collapse-btn {
  margin: var(--space-2);
  align-self: flex-start;
  flex-shrink: 0;
}

#ks-sidebar.ks-collapsed #ks-collapse-btn {
  align-self: center;
  margin: var(--space-2) auto;
}


/* ── BOTTOM TAB BAR (mobile only) ───────────────────────────── */
/* The bar's full height: its tabs plus the iPhone home-indicator strip, so the
   tabs keep their size. Pages that sit above the bar use this too. */
:root { --ks-bottombar-t: calc(var(--ks-bottombar-h) + env(safe-area-inset-bottom, 0px)); }
#ks-bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--ks-bottombar-t);
  z-index: 200;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#ks-bottombar::-webkit-scrollbar { display: none; }

.ks-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 64px;
  padding: 12px var(--space-2);
  text-decoration: none;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 11px;
  line-height: 1;
  font-weight: 600;
  transition: color 150ms ease;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ks-tab-item:hover {
  color: var(--text-muted);
}
.ks-tab-item.ks-active {
  color: var(--accent);
}
.ks-tab-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.ks-tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 22px;
  color: inherit;
  flex-shrink: 0;
}

.ks-tab-label {
  line-height: 1;
  letter-spacing: 0.02em;
}


/* ── BODY SPACING WHEN SHELL IS ACTIVE ──────────────────────── */
body.ks-active {
  padding-top: var(--ks-topbar-h);
  /*
   * _shared.css sets overflow-x:hidden on body. On iOS Safari and Chrome/Android,
   * this makes position:fixed children use the body (not the viewport) as their
   * containing block. Since the body is min-height:100vh + padding-bottom:72px,
   * a bottom:0 fixed element ends up ~72px below the visible screen.
   * Unsetting overflow-x here restores correct viewport-relative fixed positioning.
   */
  overflow-x: visible;
}

/* Desktop / tablet: sidebar pushes content right */
@media (min-width: 768px) {
  body.ks-active {
    padding-left: var(--ks-sidebar-w);
  }
  body.ks-active.ks-collapsed {
    padding-left: var(--ks-sidebar-cw);
  }
  body.ks-transitions-ready.ks-active {
    transition: padding-left 250ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Hide bottom bar on desktop */
  #ks-bottombar { display: none; }

  /* Hide hamburger tooltip on desktop (sidebar is always visible) */
  #ks-menu-toggle { display: none; }
}

/* Back, in the installed app (no browser toolbar there). */
#ks-back { flex-shrink: 0; }

/* Mobile: bottom bar pads content */
@media (max-width: 767px) {
  body.ks-active {
    padding-bottom: var(--ks-bottombar-t);
  }

  /* No sidebar or hamburger on mobile */
  #ks-sidebar,
  #ks-menu-toggle {
    display: none;
  }

  /* Top bar: no left padding gap where hamburger would be */
  #ks-topbar {
    padding-left: var(--space-4);
  }
}


/* ── MORE SHEET (mobile only) ───────────────────────────────── */
#ks-more-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: var(--ks-bottombar-t);
  z-index: 298;
  background: var(--overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}
#ks-more-backdrop.ks-open {
  opacity: 1;
  pointer-events: auto;
}

#ks-more-sheet {
  position: fixed;
  bottom: var(--ks-bottombar-t);
  left: 0; right: 0;
  z-index: 299;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  max-height: 65vh;
  overflow-y: auto;
  transform: translateY(calc(100% + var(--ks-bottombar-t)));
  /* Closed: out of the keyboard order and hidden from screen readers too. */
  visibility: hidden;
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 240ms;
}
#ks-more-sheet.ks-open {
  transform: translateY(0);
  visibility: visible;
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
}
/* Keyboard users can jump past the app menus to the page itself. */
.ks-skip {
  position: fixed; left: 12px; top: -60px; z-index: 1000;
  background: var(--surface); color: var(--ink); border: 2px solid var(--accent);
  border-radius: 10px; padding: 10px 16px; font-weight: 700; text-decoration: none;
}
.ks-skip:focus { top: 12px; }

#ks-more-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
}

#ks-more-title {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  padding: 10px var(--space-4) var(--space-2);
}

.ks-more-section {
  grid-column: 1 / -1;
  padding: var(--space-3) var(--space-2) 0;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

#ks-more-apps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: var(--space-2) var(--space-2) var(--space-6);
  gap: var(--space-1);
}

.ks-more-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  transition: background 150ms ease, color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.ks-more-app:hover,
.ks-more-app:active {
  background: var(--surface-neutral);
  color: var(--ink);
}

.ks-more-app-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--surface-neutral);
  color: var(--accent);
  flex-shrink: 0;
  transition: background 150ms ease;
}
.ks-more-app:hover .ks-more-app-icon,
.ks-more-app:active .ks-more-app-icon {
  background: var(--accent-tint);
}

.ks-more-app-label {
  word-break: break-word;
  hyphens: auto;
}

/* Pro-tier locked nav items (Planner/Markbook for non-Pro teachers) */
.ks-locked { color: var(--text-faint); }
.ks-lock-badge {
  display: inline-block;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--on-accent); background: var(--ink);   /* the black PRO pill */
  border-radius: var(--radius-pill); padding: 2px 7px;
  margin-left: auto; flex-shrink: 0;
}

@media (min-width: 768px) {
  #ks-more-backdrop,
  #ks-more-sheet { display: none; }
}

/* ── Policy notice (kredits-shell.js showPolicyNotice) ──
   Floats over the page so it never takes room from full-height tools like
   Seating; sits under modals and Seating's Full Screen (z-index 300+). */
#ks-policy-notice {
  position: fixed; right: 16px; bottom: 16px; z-index: 250;
  width: min(360px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 12px 14px; font-size: 12.5px; line-height: 1.45;
}
#ks-policy-notice .ks-pn-title { font-weight: 700; font-size: 13.5px; margin-bottom: 4px; }
#ks-policy-notice .ks-pn-body { color: var(--text-muted); }
#ks-policy-notice .ks-pn-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 10px; }
#ks-policy-notice .ks-pn-link { color: var(--accent); font-weight: 600; text-decoration: none; }
#ks-policy-notice .ks-pn-link:hover { text-decoration: underline; }
#ks-policy-notice .ks-pn-ok {
  border: none; border-radius: 10px; min-height: 36px; padding: 6px 14px; cursor: pointer; font: inherit; font-weight: 700;
  background: var(--accent); color: var(--on-accent);
}
@media (max-width: 767px) {
  #ks-policy-notice { right: 16px; bottom: calc(var(--ks-bottombar-t) + 12px); }
}
/* Most pages: a banner at the top of the content instead, in the flow, covering nothing. */
#ks-policy-notice.ks-pn-inline {
  position: static; width: auto; max-width: 1040px; margin: 0 0 16px; box-shadow: none;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
}
#ks-policy-notice.ks-pn-inline .ks-pn-body { flex: 1 1 320px; }
#ks-policy-notice.ks-pn-inline .ks-pn-title { margin: 0; flex: 0 0 auto; }
#ks-policy-notice.ks-pn-inline .ks-pn-actions { margin: 0; }
@media print { #ks-policy-notice { display: none !important; } }

/* Controls drawn as plain elements (class cards, seats, chips) show where the
   keyboard is, as real buttons do. */
[role="button"][tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Icons come from the shared Lucide sprite: give them a fixed size, as
   .k-icon otherwise follows the (small) label font size. */
.ks-nav-icon .k-icon { width: 20px; height: 20px; }
.ks-tab-icon .k-icon { width: 22px; height: 22px; }
.ks-more-app-icon .k-icon { width: 22px; height: 22px; }
.ks-more-app-icon { background: var(--accent-tint); }
