/* ============================ App shell ============================
   Sidebar + header layout, page heading, stat cards, tables and the small
   charts on the teacher overview. Loaded after dashboard.css. */

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; background: var(--surface-page); }
.shell::before { content: ""; } /* keeps the first column as the sidebar's gutter; the sidebar itself is fixed */
.shell__main { min-width: 0; display: flex; flex-direction: column; }
.shell__main > main { flex: 1 1 auto; padding: var(--space-6) var(--space-8) var(--space-12); }
@media (max-width: 1200px) { .shell__main > main { padding: var(--space-6) var(--space-6) var(--space-10); } }
@media (max-width: 640px) { .shell__main > main { padding: var(--space-4) var(--space-4) var(--space-8); } }

/* ---------- Sidebar ---------- */
.sidebar {
  /* Pinned to the window edges, so it never floats short of the bottom (the page is zoomed to 0.9) */
  position: fixed; top: 0; bottom: 0; left: 0; width: 264px; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  background: var(--surface-card); border-right: 1px solid var(--border-hairline);
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-5); text-decoration: none; color: var(--ink);
}
.sidebar__mark {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; flex-shrink: 0;
  background: linear-gradient(145deg, #ef4a5c, var(--primary)); color: #fff;
  box-shadow: 0 6px 14px rgba(215, 37, 57, 0.28);
}
.sidebar__name { display: block; font-size: 19px; line-height: 22px; font-weight: 700; letter-spacing: -0.2px; }
.sidebar__tag { display: block; font-size: 12px; line-height: 16px; color: var(--ink-muted); margin-top: 2px; }

.sidebar__group { display: grid; gap: 2px; padding-bottom: var(--space-3); margin-bottom: var(--space-2); border-bottom: 1px solid var(--border-hairline); }
.sidebar__group:last-of-type { border-bottom: 0; }
.sidebar__title { font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); padding: var(--space-2) var(--space-3) var(--space-2); }
.sidebar__link {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  padding: 10px var(--space-3); border: 1px solid transparent; border-radius: var(--radius-md);
  background: none; color: var(--ink); font: inherit; font-size: 14.5px; font-weight: 500; text-align: left; cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.sidebar__link .sicon { color: var(--ink-muted); flex-shrink: 0; }
.sidebar__link .sicon:last-child:not(:first-child) { margin-left: auto; color: var(--ink-faint); }
.sidebar__link:hover { background: var(--surface-sunken); }
.sidebar__link[aria-current="page"] {
  background: var(--surface-card); border-color: var(--border-hairline); font-weight: 600;
  box-shadow: 0 1px 2px rgba(18, 25, 38, 0.06), 0 4px 10px rgba(18, 25, 38, 0.05);
}
.sidebar__link[aria-current="page"] .sicon { color: var(--ink); }
.sidebar__link--quiet { color: var(--ink-muted); }
.sidebar__account { position: relative; }
.sidebar__menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + var(--space-1)); z-index: 5;
  display: grid; gap: 2px; padding: var(--space-1);
  background: var(--surface-card); border: 1px solid var(--border-hairline); border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
}
.sidebar__menuhead {
  display: flex; align-items: center; gap: var(--space-3); min-width: 0;
  padding: var(--space-2) var(--space-3); margin-bottom: var(--space-1); border-bottom: 1px solid var(--border-hairline);
}
.sidebar__menusep { height: 1px; margin: var(--space-1) var(--space-2); background: var(--border-hairline); }

.sidebar__foot { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--border-hairline); display: grid; gap: var(--space-2); }
.sidebar__user {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-width: 0;
  padding: var(--space-2) var(--space-3); border: 1px solid transparent; border-radius: var(--radius-md);
  background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.sidebar__user:hover { background: var(--surface-sunken); }
.sidebar__user[aria-current="page"] { background: var(--surface-card); border-color: var(--border-hairline); box-shadow: 0 1px 2px rgba(18, 25, 38, 0.06); }
.sidebar__user .sicon { margin-left: auto; color: var(--ink-faint); flex-shrink: 0; }
.avatar--lg { width: 56px; height: 56px; font-size: 18px; }
.sidebar__who { display: grid; min-width: 0; }
.sidebar__uname { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__urole { font-size: 12px; color: var(--ink-muted); }
.avatar {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary-ink); font-size: 12px; font-weight: 700; letter-spacing: 0.02em;
}
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }

/* ---------- Header ---------- */
.apphead {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-8);
  background: var(--surface-card); border-bottom: 1px solid var(--border-hairline);
}
@media (max-width: 1200px) { .apphead { padding: var(--space-3) var(--space-6); } }
@media (max-width: 640px) { .apphead { padding: var(--space-3) var(--space-4); } }
.apphead__spacer { flex: 1 1 auto; }
.apphead__menu { display: none; }
.crumbs { display: flex; align-items: center; gap: var(--space-2); font-size: 14.5px; font-weight: 500; color: var(--ink-muted); min-width: 0; }
.crumbs .sicon { color: var(--ink-faint); flex-shrink: 0; }
.crumbs__root { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.crumbs__root:hover { color: var(--primary); }
.crumbs__here { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hsearch {
  display: flex; align-items: center; gap: var(--space-2); width: 300px; max-width: 100%;
  padding: 0 var(--space-2) 0 var(--space-3); height: 40px;
  border: 1px solid var(--border-hairline); border-radius: var(--radius-md); background: var(--surface-card); color: var(--ink-muted);
}
.hsearch:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.hsearch input { flex: 1 1 auto; min-width: 0; border: 0; background: none; font: inherit; font-size: 14px; color: var(--ink); }
.hsearch input:focus { outline: none; }
.hsearch input::-webkit-search-cancel-button { -webkit-appearance: none; }
.hsearch kbd {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--ink-muted);
  border: 1px solid var(--border-hairline); border-radius: 6px; padding: 1px 7px; background: var(--surface-sunken);
}
@media (max-width: 900px) { .hsearch { width: 200px; } .hsearch kbd { display: none; } }
@media (max-width: 640px) {
  .hsearch { display: none; }
  .crumbs__here, .crumbs .sicon:nth-child(3) { display: none; }
  .hpill { padding: 0 10px; }
}
@media (max-width: 420px) { .crumbs { display: none; } }

.iconbtn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0;
  border: 1px solid var(--border-hairline); border-radius: var(--radius-md); background: var(--surface-card); color: var(--ink); cursor: pointer;
  position: relative;
}
.iconbtn:hover { background: var(--surface-sunken); }
.iconbtn__n {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--radius-pill); background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* Teacher header pills: country and syllabus */
.hpill {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 var(--space-3);
  border: 1px solid var(--border-hairline); border-radius: var(--radius-md); background: var(--surface-card);
  font: inherit; font-size: 13.5px; font-weight: 600; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.hpill:hover, .hpill[aria-expanded="true"] { background: var(--surface-sunken); }
.hpill[disabled] { color: var(--ink-muted); cursor: default; }
.hpill__chev { font-size: 10px; color: var(--ink-muted); }
.hmenu { position: relative; }
.hmenu .country-dropdown { left: auto; right: 0; }
.apphead .curriculum-popover { left: auto; right: var(--space-8); top: calc(100% - 6px); }
@media (max-width: 1200px) { .apphead .curriculum-popover { right: var(--space-6); } }

/* ---------- Page heading ---------- */
.pagehead { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.pagehead__icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  background: var(--primary); color: #fff; box-shadow: 0 4px 10px rgba(215, 37, 57, 0.25);
}
.pagehead__text { flex: 1 1 320px; min-width: 0; }
.pagehead__title { font-size: 24px; line-height: 30px; font-weight: 700; letter-spacing: -0.3px; }
.pagehead__sub { font-size: 14px; line-height: 20px; color: var(--ink-muted); margin-top: 2px; }
.pagehead__action { margin-left: auto; }
@media (max-width: 640px) { .pagehead__action { margin-left: 0; width: 100%; } .pagehead__title { font-size: 21px; line-height: 26px; } }

/* ---------- Card header (title + subtitle + action) ---------- */
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }
.card__title { font-size: 17px; line-height: 22px; font-weight: 700; letter-spacing: -0.2px; }
.card__sub { font-size: 13.5px; line-height: 19px; color: var(--ink-muted); margin-top: 2px; }

/* ---------- Stat cards ---------- */
.statrow {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface-card); border: 1px solid var(--border-hairline); border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  overflow: hidden;
}
.stat { padding: var(--space-5) var(--space-5) var(--space-5); border-right: 1px solid var(--border-hairline); min-width: 0; }
.stat:last-child { border-right: 0; }
.stat__head { display: flex; align-items: center; gap: var(--space-3); padding-bottom: var(--space-4); margin-bottom: var(--space-4); border-bottom: 1px solid var(--border-hairline); }
.stat__icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; color: #fff; flex-shrink: 0; }
.stat__icon--primary { background: var(--primary); }
.stat__icon--orange { background: #f0883e; }
.stat__icon--wine { background: var(--wine); }
.stat__icon--slate { background: var(--slate); }
.stat__label { font-size: 15px; font-weight: 500; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat__dots { margin-left: auto; color: var(--ink-faint); }
.stat__value { font-size: 28px; line-height: 32px; font-weight: 700; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.stat__note { font-size: 13px; line-height: 18px; color: var(--ink-muted); margin-top: var(--space-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }
.stat__delta { color: var(--success); font-weight: 600; }
@media (max-width: 1100px) { .statrow { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stat:nth-child(2) { border-right: 0; } .stat:nth-child(-n + 2) { border-bottom: 1px solid var(--border-hairline); } }
@media (max-width: 560px) { .statrow { grid-template-columns: 1fr; } .stat { border-right: 0; border-bottom: 1px solid var(--border-hairline); } .stat:last-child { border-bottom: 0; } }

/* ---------- Overview grid ---------- */
.dash2 { display: grid; gap: var(--space-6); grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); align-items: start; }
.dash2--wide { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .dash2, .dash2--wide { grid-template-columns: minmax(0, 1fr); } }
.quicktools { display: grid; gap: var(--space-3); }
/* Grid children must be allowed to shrink, or a wide table stretches the whole page */
.stack > *, .dash2 > *, .shell__main > main > * { min-width: 0; }

/* ---------- Bar chart ---------- */
.barchart { padding-top: var(--space-3); }
.barchart__bars { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--space-3); height: 200px; align-items: end; }
.barchart__col { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100%; align-items: end; justify-items: center; gap: var(--space-2); min-width: 0; }
.barchart__bar {
  position: relative; display: block; width: min(34px, 100%); border-radius: 8px 8px 4px 4px; background: var(--primary); align-self: end;
  transition: height 300ms ease;
}
.barchart__bar[data-empty] { background: var(--track); }
.barchart__tip {
  position: absolute; left: 50%; top: -24px; transform: translateX(-50%);
  font-size: 12px; font-weight: 600; color: var(--ink); background: var(--surface-card); border: 1px solid var(--border-hairline); border-radius: 6px; padding: 0 6px; line-height: 18px;
  opacity: 0; transition: opacity 120ms ease; pointer-events: none;
}
.barchart__col:hover .barchart__tip { opacity: 1; }
.barchart__x { font-size: 11.5px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------- Ranked bars ---------- */
.rank { display: grid; gap: var(--space-3); }
.rank__row { display: grid; grid-template-columns: minmax(0, 1fr) 36px; grid-template-areas: "name n" "track n"; gap: 4px var(--space-3); align-items: center; }
.rank__name { grid-area: name; font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank__track { grid-area: track; height: 8px; border-radius: var(--radius-pill); background: var(--track); overflow: hidden; }
.rank__fill { display: block; height: 100%; background: var(--primary); border-radius: var(--radius-pill); }
.rank__n { grid-area: n; font-size: 13.5px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Data tables ---------- */
.tablewrap { overflow-x: auto; margin: 0 calc(-1 * var(--space-6)); padding: 0 var(--space-6); }
@media (max-width: 520px) { .tablewrap { margin: 0 calc(-1 * var(--space-4)); padding: 0 var(--space-4); } }
.dtable { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.dtable th, .dtable td { text-align: left; vertical-align: middle; padding: 12px var(--space-3); border-bottom: 1px solid var(--border-hairline); }
.dtable th:first-child, .dtable td:first-child { padding-left: 0; }
.dtable th:last-child, .dtable td:last-child { padding-right: 0; }
.dtable thead th { position: relative; font-size: 13px; font-weight: 500; color: var(--ink-muted); border-bottom-color: var(--border-hairline); white-space: nowrap; }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tbody tr:hover td { background: var(--surface-sunken); }
.dtable__main { font-weight: 600; }
.dtable__dim { color: var(--ink-muted); white-space: nowrap; }
.dtable__act { text-align: right; white-space: nowrap; }
.dtable__act .btn + .btn { margin-left: var(--space-2); }
.dtable__who { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.dtable__who .studentlink { text-decoration: none; }
.dtable__who .studentlink:hover { color: var(--primary); }
.dtable tr.is-spacer td { border-bottom-color: transparent; }
.dtable tr.is-spacer:hover td { background: none; }
/* A visually hidden header label is positioned absolutely, so its cell must contain it */
.bptable th, .docassign th { position: relative; }
/* Narrow screens: tables keep their columns and scroll sideways inside the card */
@media (max-width: 760px) {
  .dtable, .bptable { min-width: 600px; }
  .dtable th, .dtable td { padding: 10px var(--space-3); }
  .stu-tablewrap { margin: 0 calc(-1 * var(--space-4)); padding: 0 var(--space-4); }
  .tablewrap::after, .stu-tablewrap::after { content: ""; display: block; height: 1px; }
}
@media (max-width: 520px) {
  .barchart__col:nth-child(even) .barchart__x { visibility: hidden; }
  .barchart__bars { gap: var(--space-2); height: 160px; }
  .card__head { flex-wrap: wrap; }
  .card__head > .toolsbar__search, .card__head > .control { width: 100%; }
}

/* Status words: coloured text, no box, like the reference table */
.status { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.status--ok { color: var(--success); }
.status--warn { color: var(--warning); }
.status--info { color: var(--primary); }
.status--bad { color: var(--danger); }
.status--muted { color: var(--ink-muted); }

/* ---------- Narrow screens: sidebar slides in ---------- */
@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { width: 280px; z-index: 60; transform: translateX(-100%); transition: transform 200ms ease; box-shadow: none; }
  .shell::before { display: none; }
  .sidebar--open { transform: none; box-shadow: 0 20px 50px rgba(18, 25, 38, 0.25); }
  .shell__scrim { position: fixed; inset: 0; z-index: 55; background: rgba(18, 25, 38, 0.4); }
  .apphead__menu { display: inline-grid; }
}

/* Encyclopedia screen: its frame fills everything below the header, which then never scrolls. */
/* Pinned to the window edges rather than sized in vh, which the page's zoom would shrink. */
html[data-route="encyclopedia"] .shell { position: fixed; inset: 0; min-height: 0; }
html[data-route="encyclopedia"] .shell__main { min-height: 0; }
html[data-route="encyclopedia"] .shell__main > main { display: flex; min-height: 0; padding: 0; }
.encframe { flex: 1 1 auto; width: 100%; min-width: 0; border: 0; display: block; background: var(--surface-page); }

/* Profile: settings rows inside a card */
.setcard { padding-bottom: var(--space-2); }
.setcard__title { margin-bottom: var(--space-2); }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; padding: var(--space-3) 0; border-top: 1px solid var(--border-hairline); }
.setrow__text { flex: 1 1 240px; min-width: 0; }
.setrow__title { font-weight: 600; }
.setrow__meter { width: 120px; height: 8px; border-radius: var(--radius-pill); background: var(--track); overflow: hidden; }
.setrow__meter span { display: block; height: 100%; background: var(--primary); }
.setrow__meter--out span { background: var(--danger); }
