/* ============================================================
   BARAEM GRADEFLOW — ANALYTICS DESIGN SYSTEM
   Enterprise analytics surface: dense, quiet, scannable. No gradients, no
   decorative illustration, no fake depth. Hierarchy comes from spacing, weight
   and one accent colour, so a teacher can read a KPI row in under a second.

   Sizing note: every panel icon is explicitly sized. A bare `svg` inside a flex
   heading inherits `max-width:100%` and stretches to its container — that bug
   once produced a 1092px blue block over the charts.
   ============================================================ */

/* ============================================================
   Tokens — mapped onto the existing design system rather than inventing a
   parallel palette, so analytics inherits the app's own visual language.
   ============================================================ */
.an-wrap, .an-bar, .an-panel, .an-kpi {
  --an-bg:        var(--surface, #fff);
  --an-text:      var(--text, #14181d);
  --an-muted:     var(--text-faint, #7b8592);
  --an-line:      var(--border, #e3e7ec);
  --an-line-2:    var(--ink-100, #f0f3f6);
  --an-hover:     var(--ink-50, #f7f9fb);
  --an-soft:      var(--ink-50, #f7f9fb);
  --an-panel-head:var(--ink-50, #f7f9fb);
  --an-accent:    var(--accent, #235a95);
  --an-accent-soft:var(--accent-soft, #f1f7fc);
  --an-accent-line:var(--brand-100, #dce9f6);
  --an-ok:        var(--green-600, #1c7a4a);
  --an-bad:       var(--red-600, #b3261e);
  --an-warn:      var(--amber-600, #a06a06);
  --an-bad-soft:  var(--red-100, #fce3e1);
  --an-mono:      ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* chart-local aliases so charts.js works on light or dark */
  --ch-card:      var(--an-bg);
  --ch-text:      var(--an-text);
  --ch-muted:     var(--an-muted);
  --ch-grid:      var(--an-line);
  --ch-accent:    var(--an-accent);
  --ch-a1:        var(--green-600, #1c7a4a);
  --ch-a2:        var(--brand-600, #235a95);
  --ch-a3:        var(--gold-600, #a8791a);
  --ch-a4:        var(--teal-600, #0d7d72);
  --ch-ok:        var(--an-ok);
  --ch-bad:       var(--an-bad);
}

/* ---------- filter bar ---------- */
.an-bar {
  position: sticky; top: 0; z-index: 30;
  background: var(--an-bg, #fff);
  border-bottom: 1px solid var(--an-line);
  padding: 10px 0 0;
  margin-bottom: 18px;
}
.an-bar-in {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end;
}
.an-fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.an-lbl {
  font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--an-muted);
}
.an-sel {
  appearance: none; -webkit-appearance: none;
  background: var(--an-bg); color: var(--an-text);
  border: 1px solid var(--an-line); border-radius: 8px;
  padding: 7px 28px 7px 10px; font-size: .84rem; font-weight: 600;
  min-width: 132px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color .15s, box-shadow .15s;
}
.an-sel:hover { border-color: var(--an-line-2); }
.an-sel:focus-visible { outline: 2px solid var(--an-accent); outline-offset: 1px; }
.an-multi { min-height: 34px; padding: 5px 10px; }
.an-multi[multiple] { background-image: none; padding-right: 10px; }
.an-bar-act { display: flex; gap: 8px; margin-inline-start: auto; }
.an-active { padding: 8px 0 2px; }

/* ---------- active-filter chip ---------- */
.an-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 700; letter-spacing: .01em;
  color: var(--an-accent);
  background: var(--an-accent-soft);
  border: 1px solid var(--an-accent-line);
  border-radius: 999px; padding: 3px 11px;
}

/* ---------- KPI row ---------- */
.an-kpis {
  display: grid; gap: 1px;
  grid-template-columns: repeat(auto-fit, minmax(146px, 1fr));
  background: var(--an-line);
  border: 1px solid var(--an-line);
  border-radius: 12px; overflow: hidden;
  margin-bottom: 16px;
}
.an-kpi { background: var(--an-bg); padding: 13px 15px 14px; min-width: 0; }
.an-kpi-k {
  font-size: .66rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--an-muted); margin-bottom: 5px;
}
.an-kpi-v {
  font-size: 1.5rem; font-weight: 750; line-height: 1.05;
  color: var(--an-text); font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-kpi-s {
  font-size: .7rem; color: var(--an-muted); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-kpi.up .an-kpi-v { color: var(--an-ok); }
.an-kpi.down .an-kpi-v { color: var(--an-bad); }

/* ---------- panels ---------- */
.an-grid {
  display: grid; gap: 14px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}
.an-panel {
  background: var(--an-bg);
  border: 1px solid var(--an-line);
  border-radius: 12px;
  overflow: hidden;
  min-width: 0;
}
.an-panel-h {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 15px; border-bottom: 1px solid var(--an-line);
  background: var(--an-panel-head);
}
/* The icon is a fixed size on purpose — see the note at the top of this file. */
.an-panel-h h3 {
  margin: 0; font-size: .875rem; font-weight: 700;
  color: var(--an-text); letter-spacing: -.01em;
  display: flex; align-items: center; gap: 8px;
  min-width: 0; flex: 0 1 auto;
}
.an-panel-h svg {
  width: 15px; height: 15px; flex: 0 0 15px;
  max-width: 15px; min-width: 15px; color: var(--an-muted);
}
.an-panel-s {
  margin-inline-start: auto; font-size: .7rem; color: var(--an-muted);
  font-weight: 600; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.an-panel-b { padding: 14px 15px 16px; min-width: 0; }
.an-note { font-size: .72rem; color: var(--an-muted); padding-top: 8px; }

/* ---------- charts ---------- */
/* The chart box is capped so an SVG never stretches to 2500px on a wide
   monitor; it centres instead. */
.an-panel-b .ch { max-width: 720px; display: block; margin: 0 auto; width: 100%; }
.ch-empty { color: var(--an-muted); }

/* ---------- tables ---------- */
.an-scroll { overflow-x: auto; margin: -4px -4px 0; padding: 4px; }
.an-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.an-table th {
  text-align: start; font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--an-muted); padding: 7px 9px;
  border-bottom: 1px solid var(--an-line); white-space: nowrap;
  position: sticky; top: 0; background: var(--an-bg);
}
.an-table td {
  padding: 7px 9px; border-bottom: 1px solid var(--an-line-2);
  color: var(--an-text); white-space: nowrap;
}
.an-table tbody tr:hover td { background: var(--an-hover); }
.an-table .num { text-align: end; font-variant-numeric: tabular-nums; }
.an-table .up { color: var(--an-ok); font-weight: 650; }
.an-table .down { color: var(--an-bad); font-weight: 650; }

/* ---------- insights ---------- */
.an-ins { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.an-in {
  border-inline-start: 3px solid var(--an-line-2);
  background: var(--an-soft); border-radius: 0 8px 8px 0;
  padding: 9px 12px;
}
.an-in p { margin: 0; font-size: .84rem; line-height: 1.5; color: var(--an-text); }
.an-in code {
  display: inline-block; margin-top: 5px;
  font-size: .69rem; color: var(--an-muted);
  font-family: var(--an-mono, ui-monospace, monospace);
  background: var(--an-bg); border: 1px solid var(--an-line);
  border-radius: 5px; padding: 1px 6px;
}
.an-in.up   { border-inline-start-color: var(--an-ok); }
.an-in.down { border-inline-start-color: var(--an-bad); }
.an-in.warn { border-inline-start-color: var(--an-warn); }
.an-in.flat { border-inline-start-color: var(--an-line-2); }

/* ---------- states ---------- */
.an-empty { text-align: center; padding: 46px 20px; }
.an-empty-i {
  width: 60px; height: 60px; margin: 0 auto 12px;
  display: grid; place-items: center; border-radius: 14px;
  background: var(--an-soft); color: var(--an-muted);
}
.an-empty h3 { margin: 0 0 5px; font-size: .95rem; font-weight: 700; color: var(--an-text); }
.an-empty p { margin: 0 0 14px; font-size: .82rem; color: var(--an-muted); max-width: 46ch; }
.an-empty.err .an-empty-i { background: var(--an-bad-soft); color: var(--an-bad); }

.an-skel { display: grid; gap: 10px; }
.sk-row {
  height: 46px; border-radius: 10px;
  background: linear-gradient(90deg, var(--an-soft) 25%, var(--an-hover) 37%, var(--an-soft) 63%);
  background-size: 400% 100%;
  animation: an-shimmer 1.3s ease-in-out infinite;
}
.sk-row.tall { height: 190px; }
@keyframes an-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .sk-row { animation: none; }
}

.an-foot {
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid var(--an-line);
  font-size: .72rem; color: var(--an-muted); line-height: 1.5;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .an-grid { grid-template-columns: 1fr; }
  .an-bar-in { gap: 8px 10px; }
  .an-sel { min-width: 0; flex: 1 1 138px; }
  .an-bar-act { width: 100%; margin-inline-start: 0; }
  .an-bar-act .btn { flex: 1; }
  .an-kpis { grid-template-columns: repeat(2, 1fr); }
  .an-kpi-v { font-size: 1.25rem; }
  .an-panel-s { display: none; }
}
@media (max-width: 560px) {
  .an-kpis { grid-template-columns: 1fr 1fr; }
  .an-kpi { padding: 10px 12px; }
  .an-kpi-v { font-size: 1.1rem; }
  .an-panel-b { padding: 11px 12px 13px; }
}
