/* Component styles. One file per component would multiply requests
   without a build step; keeping them together for now. */

/* Stat tile */
.stat-tile { border-radius: var(--radius-md); }
.stat-tile .card-body { padding: var(--space-4) var(--space-5); }
.stat-tile .stat-label {
  font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: .06em; color: var(--color-text-muted);
  font-weight: var(--weight-semibold); margin-bottom: var(--space-1);
}
.stat-tile .stat-value {
  font-size: var(--text-3xl); line-height: var(--lh-3xl);
  font-weight: var(--weight-semibold); color: var(--color-text);
  letter-spacing: -0.01em;
}
.stat-tile .stat-delta { font-size: var(--text-xs); margin-top: var(--space-1); }
.stat-tile .stat-delta.is-up   { color: var(--color-success-ink); }
.stat-tile .stat-delta.is-down { color: var(--color-danger-ink); }

/* Chip (badge), tone variants that resolve from tokens */
.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  line-height: 1.4;
}
.chip--neutral { background: var(--color-surface-alt); color: var(--color-text-muted); }
.chip--primary { background: var(--color-primary-soft); color: var(--color-primary); }
.chip--success { background: var(--color-success-soft); color: var(--color-success-ink); }
.chip--warning { background: var(--color-warning-soft); color: var(--color-warning-ink); }
.chip--danger  { background: var(--color-danger-soft);  color: var(--color-danger-ink); }
.chip--info    { background: var(--color-info-soft);    color: var(--color-info-ink); }

/* Empty state */
.empty-state {
  padding: var(--space-10) var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
}
.empty-state .empty-icon {
  font-size: 44px; color: var(--color-text-subtle);
  margin-bottom: var(--space-3);
  line-height: 1;
}
.empty-state .empty-title {
  color: var(--color-text); font-weight: var(--weight-semibold);
  font-size: var(--text-lg); margin-bottom: var(--space-2);
}
.empty-state .empty-body { max-width: 380px; margin: 0 auto; }

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg,
    var(--color-surface-alt) 0%,
    var(--color-border) 50%,
    var(--color-surface-alt) 100%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1400ms linear infinite;
  border-radius: var(--radius-sm);
  color: transparent;
}
.skeleton-line { height: 12px; margin-bottom: var(--space-2); }
.skeleton-line.is-title { height: 18px; width: 40%; }
@keyframes skeletonShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Form action row used at the bottom of a form (esp. inside modals). */
.form-actions {
  display: flex; justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}
.form-actions.start { justify-content: flex-start; }

/* Big number tile used on the dashboard for single-count widgets. */
.big-number {
  font-size: var(--text-3xl);
  line-height: var(--lh-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  color: var(--color-text);
}
.big-number[data-tone="primary"] { color: var(--color-primary); }
.big-number[data-tone="success"] { color: var(--color-success-ink); }
.big-number[data-tone="warning"] { color: var(--color-warning-ink); }
.big-number[data-tone="danger"]  { color: var(--color-danger-ink); }
.big-number[data-tone="info"]    { color: var(--color-info-ink); }

/* Progress bar for token-driven meters. */
.meter { height: 14px; background: var(--color-surface-alt); border-radius: 999px; overflow: hidden; }
.meter > .meter-fill { height: 100%; background: var(--color-primary); transition: width var(--dur-md) var(--ease-out); }

/* Signature underline on printable pages. */
.signature-line { height: 32px; border-bottom: 1px solid var(--color-border-strong); }

/* Chart container with fixed responsive height. */
.chart-canvas-wrap { height: 200px; }
.chart-canvas-wrap.tall { height: 240px; }

/* Score-distribution histogram used in the results review page. */
.histogram { display: flex; align-items: flex-end; gap: 4px; height: 120px; margin-top: var(--space-3); }
.histogram-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.histogram-bar { width: 100%; background: var(--color-primary); border-radius: 3px 3px 0 0; min-height: 2px; }
.histogram-label { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-1); }

/* Column-width utility on tables. */
.col-meter  { width: 40%; }
.col-narrow { width: 15%; }
.col-position { width: 80px; }

/* Pre-wrap paragraph in dl rows. */
.pre-wrap { white-space: pre-wrap; }

/* Tabs (underline style) */
.tabs {
  display: flex; gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  overflow-y: hidden;
}
/* Reset the browser's default <button> chrome so a .tab looks like a text
   link with an underline, not a pill-shaped grey box. */
button.tab, .tab {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: var(--space-3) var(--space-4);
  margin-bottom: -1px;
  color: var(--color-text-muted);
  font: inherit;
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  line-height: 1.25;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-xs) var(--ease-out), border-color var(--dur-sm) var(--ease-out);
}
.tab:hover { color: var(--color-text); text-decoration: none; }
.tab:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-xs); }
.tab.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* Tab panels - one visible at a time inside a .tab-group[data-tabs] */
.tab-group { display: block; }
.tab-panels { display: block; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.tab-panel[hidden] { display: none !important; }

/* Data table that must not wrap its cells. The .table itself keeps its
   natural content width; the enclosing .data-table-scroll clips + scrolls. */
.data-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.data-table-scroll > table { width: max-content; min-width: 100%; margin: 0; }
.data-table-scroll th,
.data-table-scroll td { white-space: nowrap; vertical-align: middle; }

/* Data-table toolbar (search + page size + bulk actions) */
.dt-toolbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  flex-wrap: wrap;
}
.dt-toolbar .dt-search { max-width: 260px; }
.dt-toolbar .dt-pagesize { display: flex; align-items: center; gap: var(--space-2); margin: 0; }
.dt-toolbar .dt-pagesize select { width: auto; }
.dt-toolbar .dt-bulk { display: flex; align-items: center; gap: var(--space-2); }
.dt-toolbar .dt-status { white-space: nowrap; }

/* Sortable header cells - applies wherever a table[data-table] lives
   (data-table-scroll wrappers, Bootstrap table-responsive, plain divs). */
table[data-table] th.dt-sortable { cursor: pointer; user-select: none; position: relative; }
table[data-table] th.dt-sortable:hover { color: var(--color-text); }
table[data-table] th.dt-sortable::after {
  content: ''; display: inline-block; width: 8px; height: 8px; margin-left: 6px; opacity: .35;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
  vertical-align: middle;
}
table[data-table] th.dt-sort-asc::after  { opacity: 1; }
table[data-table] th.dt-sort-desc::after { opacity: 1; transform: rotate(180deg); }

/* Selection column */
table[data-table] th.dt-select-col,
table[data-table] td.dt-select-col { width: 32px; text-align: center; }

/* Pager */
.dt-pager {
  display: flex; gap: var(--space-1); justify-content: flex-end;
  padding: var(--space-2) var(--space-3);
  flex-wrap: wrap;
}
.dt-page-btn {
  appearance: none; background: transparent; border: 1px solid var(--color-border);
  color: var(--color-text-muted); border-radius: var(--radius-sm);
  padding: 4px 10px; font-size: var(--text-sm); cursor: pointer;
  min-width: 32px;
}
.dt-page-btn:hover:not(:disabled) { background: var(--color-surface-alt); color: var(--color-text); }
.dt-page-btn:disabled { opacity: .4; cursor: not-allowed; }
.dt-page-btn.is-active { background: var(--color-primary-soft); border-color: transparent; color: var(--color-primary); font-weight: var(--weight-semibold); }

/* Full-screen loading overlay for slow POSTs (import commit, etc.) */
.sims-loading-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(15, 23, 32, .45);
  display: flex; align-items: center; justify-content: center;
  animation: overlayFade .18s ease-out;
}
.sims-loading-overlay .card {
  min-width: 280px; max-width: 420px; padding: var(--space-5);
  text-align: center;
}
.sims-loading-overlay .sims-spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  margin: 0 auto var(--space-3);
  animation: spin .9s linear infinite;
}
.sims-loading-overlay .sims-progress {
  height: 6px; background: var(--color-surface-alt); border-radius: 999px; overflow: hidden;
  margin-top: var(--space-3);
}
.sims-loading-overlay .sims-progress > span {
  display: block; height: 100%; background: var(--color-primary);
  width: 30%; animation: indeterminate 1.4s ease-in-out infinite;
}
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes indeterminate {
  0%   { margin-left: -40%; width: 30%; }
  50%  { margin-left: 40%; width: 50%; }
  100% { margin-left: 110%; width: 30%; }
}

/* Import-hub side nav */
.import-nav {
  display: block; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); color: var(--color-text);
  font-size: var(--text-sm);
  transition: background var(--dur-xs) var(--ease-out);
}
.import-nav:hover { background: var(--color-surface-alt); text-decoration: none; }
.import-nav.is-active { background: var(--color-primary-soft); color: var(--color-primary); font-weight: var(--weight-medium); }

/* Section header inside cards */
.section-heading {
  font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: .06em; color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
  margin: 0 0 var(--space-2);
}

/* Breadcrumb trail (templates/components/breadcrumbs.php) */
.breadcrumbs { margin: 0 0 var(--space-3); font-size: var(--text-sm); }
.breadcrumbs ol { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0; align-items: center; }
.breadcrumbs li { display: inline-flex; align-items: center; color: var(--color-text-muted); }
.breadcrumbs a { color: var(--color-text-muted); text-decoration: none; padding: 2px 4px; border-radius: var(--radius-xs); }
.breadcrumbs a:hover { color: var(--color-primary); background: var(--color-surface-alt); text-decoration: none; }
.breadcrumbs li[aria-current="page"] > span { color: var(--color-text); font-weight: var(--weight-medium); padding: 2px 4px; }
.breadcrumbs .sep { color: var(--color-border-strong); margin: 0 var(--space-1); user-select: none; }

/* Components that resolved their colours from Bootstrap's or Tom
   Select's own light-mode defaults rather than from our tokens.
   In dark mode each of these rendered dark text on a dark panel, or a
   light panel in the middle of a dark page. Found by walking every
   page and measuring contrast, not by eye. */

/* Tom Select: the selected value, the dropdown, and its rows. The
   dropdown is what a school sees when picking a subject or a class. */
.ts-control,
.ts-wrapper.single .ts-control,
.ts-dropdown {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.ts-control .item,
.ts-dropdown .option,
.ts-dropdown .create,
.ts-dropdown .no-results { color: var(--color-text); }
.ts-dropdown .optgroup-header {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
}
.ts-dropdown .active { background: var(--color-primary-soft); color: var(--color-text); }
.ts-dropdown [data-selectable] .highlight { background: var(--color-warning-soft); color: var(--color-text); }
.ts-wrapper.multi .ts-control > div {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}
.ts-wrapper.multi .ts-control > div.active {
  background: var(--color-primary);
  color: var(--color-on-accent);
}
.ts-control input, .ts-control input::placeholder { color: var(--color-text-muted); }

/* An addon on a field, such as the % after a weight. Bootstrap fills
   it with its own near-white. */
.input-group-text {
  background-color: var(--color-surface-alt);
  border-color: var(--color-border);
  color: var(--color-text);
}

/* A link inside an alert. Bootstrap darkens it from the alert's own
   colour, which on a dark alert lands almost on the background. */
.alert-link { color: inherit; text-decoration: underline; }

/* Bootstrap's subtle badges and text-bg-* labels, as tints of their hue
   (base.css has the reasoning). Bootstrap fills these from its own
   palette, which is neither the school's colour nor either theme's. */
.badge.bg-secondary-subtle, .badge.text-secondary, .badge.text-body-secondary,
.text-bg-secondary, .text-bg-light {
  background-color: var(--color-surface-alt) !important;
  color: var(--color-text-muted) !important;
}
.badge.bg-primary-subtle, .text-bg-primary { background-color: var(--color-primary-soft) !important; color: var(--color-primary) !important; }
.badge.bg-success-subtle, .text-bg-success { background-color: var(--color-success-soft) !important; color: var(--color-success-ink) !important; }
.badge.bg-warning-subtle, .text-bg-warning { background-color: var(--color-warning-soft) !important; color: var(--color-warning-ink) !important; }
.badge.bg-danger-subtle,  .text-bg-danger  { background-color: var(--color-danger-soft) !important;  color: var(--color-danger-ink) !important; }
.badge.bg-info-subtle,    .text-bg-info    { background-color: var(--color-info-soft) !important;    color: var(--color-info-ink) !important; }

/* Bootstrap colours that stay near-black or near-white in both themes. */
.text-dark { color: var(--color-text) !important; }
.bg-body { background-color: var(--color-bg) !important; }
.border-secondary { border-color: var(--color-border-strong) !important; }
.btn-light {
  --bs-btn-bg: var(--color-surface-alt); --bs-btn-border-color: var(--color-border);
  --bs-btn-color: var(--color-text);
  --bs-btn-hover-bg: var(--color-border); --bs-btn-hover-border-color: var(--color-border-strong);
  --bs-btn-hover-color: var(--color-text);
  --bs-btn-active-bg: var(--color-border); --bs-btn-active-border-color: var(--color-border-strong);
  --bs-btn-active-color: var(--color-text);
}
/* A flagged or summary table row is a tint, so it follows the theme. */
.table > :not(caption) > tr.table-warning { --bs-table-bg: var(--color-warning-soft); --bs-table-color: var(--color-text); --bs-table-border-color: var(--color-border); }
.table > :not(caption) > tr.table-success { --bs-table-bg: var(--color-success-soft); --bs-table-color: var(--color-text); --bs-table-border-color: var(--color-border); }
.table > :not(caption) > tr.table-danger  { --bs-table-bg: var(--color-danger-soft);  --bs-table-color: var(--color-text); --bs-table-border-color: var(--color-border); }
.table > :not(caption) > tr.table-info    { --bs-table-bg: var(--color-info-soft);    --bs-table-color: var(--color-text); --bs-table-border-color: var(--color-border); }
.table > :not(caption) > tr.table-active  { --bs-table-bg-state: var(--color-surface-alt); --bs-table-color-state: var(--color-text); }

/* Tom Select's arrow, in the theme's muted colour like a plain select. */
.ts-wrapper.single.form-select {
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: 16px 12px;
}

/* Bootstrap sets a button's colour through --bs-btn-color, which wins
   over a plain `color` declaration wherever its own rule comes later.
   The secondary button is neutral (base.css), so its text is the text
   colour: on-accent here once put white text on a light grey button. */
.btn-outline-secondary { --bs-btn-color: var(--color-text); --bs-btn-hover-color: var(--color-text); }
.btn-secondary { --bs-btn-color: var(--color-text); --bs-btn-hover-color: var(--color-text); }

/* Bootstrap's neutral fills, which stay near-white whatever the theme. */
.bg-light, .bg-body-tertiary, .bg-body-secondary, .text-bg-light {
  background-color: var(--color-surface-alt) !important;
  color: var(--color-text) !important;
}

/* Alerts. Bootstrap builds each variant from its own *-bg-subtle and
   *-text-emphasis, which it only redefines under [data-bs-theme=dark].
   This app themes itself through its own tokens, so an alert stayed a
   near-white panel in the middle of a dark page. */
.alert-secondary, .alert-light, .alert-dark {
  --bs-alert-bg: var(--color-surface-alt);
  --bs-alert-color: var(--color-text);
  --bs-alert-border-color: var(--color-border);
}
.alert-primary { --bs-alert-bg: var(--color-primary-soft); --bs-alert-color: var(--color-text); --bs-alert-border-color: var(--color-border); }
/* The toned alerts take their colours in base.css, which states them
   outright rather than through Bootstrap's variables. */

/* A disabled button still has to be read, or nobody learns why it is
   disabled from the tooltip that explains it. */
.btn:disabled, .btn.disabled { --bs-btn-disabled-color: var(--color-text-muted); }

/* Bootstrap tints several surfaces with a percentage of this, and its
   default is a near-black that does not belong in the dark palette (the
   dark value is in theme-dark.css). */
:root { --bs-body-color-rgb: 26, 32, 40; }

/* table-stack: on a phone each row becomes a card, and each cell shows
   its column name from data-label. For settings tables whose cells hold
   form controls, which cannot shrink to fit side by side. */
@media (max-width: 640px) {
  table.table-stack, table.table-stack tbody, table.table-stack tr, table.table-stack td { display: block; width: 100%; }
  table.table-stack thead { display: none; }
  table.table-stack tr { border: 1px solid var(--border, #dee2e6); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
  table.table-stack td { border: 0; padding: 4px 0 !important; text-align: left !important; }
  table.table-stack td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--text-muted, #6c757d); margin-bottom: 2px; }
  table.table-stack td.stack-hide { display: none; }
  .card-body.p-0 > table.table-stack, .card > table.table-stack,
  .card-body.p-0 > .table-responsive > table.table-stack { padding: 12px 12px 2px; }
}

/* Performance bars on the parent portal: pupil against class average. */
.perf-row { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.perf-name { width: 34%; min-width: 0; font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perf-bars { flex: 1; min-width: 0; }
.perf-bar { height: 8px; border-radius: 4px; }
.perf-bar + .perf-bar { margin-top: 3px; }
.perf-bar--me { background: var(--color-primary, #0d6efd); }
.perf-bar--avg { background: var(--color-border-strong, #b9c0ca); }
.perf-num { width: 70px; text-align: right; font-size: .875rem; white-space: nowrap; }
.perf-key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; }

/* Report picker on the parent portal's term section. */
.report-menu { position: relative; }
.report-menu > summary { list-style: none; }
.report-menu > summary::-webkit-details-marker { display: none; }
.report-menu-list { position: absolute; right: 0; z-index: 20; margin-top: 6px; min-width: 280px; padding: 10px 12px;
  background: var(--color-surface, #fff); border: 1px solid var(--color-border, #dee2e6); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.report-menu-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; font-size: .875rem; }

/* User monitoring. The section tabs scroll sideways on a phone instead
   of wrapping into a stack, and a KPI tile that leads somewhere is one
   link with a visible focus. */
.monitoring-nav { overflow-x: auto; scrollbar-width: thin; margin-bottom: var(--space-3); }
.monitoring-nav .nav-tabs { flex-wrap: nowrap; margin-bottom: 0; }
.monitoring-nav .nav-link { white-space: nowrap; }
.monitoring-subnav { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.kpi-link { display: block; height: 100%; color: inherit; text-decoration: none; border-radius: var(--radius-md); }
.kpi-link .stat-tile { height: 100%; }
.kpi-link:hover .stat-tile, .kpi-link:focus-visible .stat-tile { border-color: var(--color-primary); }
.kpi-note { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-1); }
.list-meta { font-size: var(--text-sm); color: var(--color-text-muted); }
/* The current choice in a monitoring tab row or toggle is a tint, as the
   current table page is, so a page still has one fill. */
.monitoring-subnav .btn[aria-current="page"], .monitoring-toggle .btn[aria-current="page"] {
  background: var(--color-primary-soft); border-color: transparent; color: var(--color-primary); font-weight: var(--weight-medium);
}
