/* ── Acadlix Addon – Responsive Category Reports (v2) ───────────────────── */
/* Rebuilt for 10+ categories: card grid, SVG rings, search/filter, horizontal charts */

/* ── Design tokens ───────────────────────────────────────────────────────── */
.aar {
  --aa-font:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --aa-bg:     #f8fafc;
  --aa-white:  #ffffff;
  --aa-border: #e2e8f0;
  --aa-text:   #0f172a;
  --aa-muted:  #64748b;
  --aa-radius: 12px;
  --aa-shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 14px rgba(0,0,0,.04);
  --aa-shadow-h: 0 4px 12px rgba(0,0,0,.11), 0 8px 28px rgba(0,0,0,.06);
  font-family: var(--aa-font);
  color: var(--aa-text);
  margin: 24px 0;
}

/* ── Notice ──────────────────────────────────────────────────────────────── */
.aar-notice {
  display: flex; align-items: flex-start; gap: 10px;
  background: #eff6ff; border-left: 4px solid #3b82f6;
  border-radius: var(--aa-radius); padding: 14px 18px;
  color: #1e40af; font-size: .93rem; line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.aar-header {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 20px;
}
.aar-header__icon { font-size: 2rem; line-height: 1; flex-shrink: 0; }
.aar-header__title {
  font-size: 1.45rem; font-weight: 800; margin: 0 0 3px;
  line-height: 1.2; color: var(--aa-text);
}
.aar-header__sub { margin: 0; font-size: .88rem; color: var(--aa-muted); }

/* ── KPI Strip ───────────────────────────────────────────────────────────── */
.aar-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.aar-kpi {
  background: var(--aa-white);
  border-radius: var(--aa-radius);
  border-top: 3px solid var(--kc, #6366f1);
  padding: 14px 16px 12px;
  box-shadow: var(--aa-shadow);
}
.aar-kpi__v {
  display: block;
  font-size: 1.7rem; font-weight: 800; line-height: 1;
  color: var(--kc, #6366f1); margin-bottom: 4px;
}
.aar-kpi__l {
  display: block;
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--aa-muted);
}

/* ── Chart Box ───────────────────────────────────────────────────────────── */
.aar-chart-box {
  background: var(--aa-white);
  border-radius: var(--aa-radius);
  box-shadow: var(--aa-shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

/* Tab bar — horizontal scroll, no visible scrollbar */
.aar-tabs {
  display: flex; flex-wrap: nowrap; overflow-x: auto;
  gap: 2px; padding: 10px 12px 0;
  background: #f8fafc;
  border-bottom: 1px solid var(--aa-border);
  scrollbar-width: none;
}
.aar-tabs::-webkit-scrollbar { display: none; }

.aar-tab {
  flex-shrink: 0;
  background: transparent; border: none;
  border-bottom: 3px solid transparent;
  padding: 8px 13px;
  font-size: .81rem; font-weight: 600;
  color: var(--aa-muted); cursor: pointer;
  border-radius: 6px 6px 0 0;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
}
.aar-tab:hover { color: var(--aa-text); background: rgba(0,0,0,.03); }
.aar-tab.is-active { color: #6366f1; border-bottom-color: #6366f1; background: var(--aa-white); }

/* Chart scroll wrapper — horizontal scroll on mobile for wide charts */
.aar-chart-scroll {
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

/*
  Auto-height for horizontal bar charts:
  --aar-n is set inline from PHP (number of categories)
  36 px per bar row + 80 px overhead, clamped 260–600px.
  JS adds .aar-chart-wrap--fixed for radar/doughnut.
*/
.aar-chart-wrap {
  height: max(260px, min(600px, calc(var(--aar-n, 8) * 36px + 80px)));
  min-width: 300px;
  padding: 18px 20px 14px;
  box-sizing: border-box;
  position: relative;
}
.aar-chart-wrap--fixed { height: 340px !important; }

.aar-canvas { width: 100% !important; height: 100% !important; display: block; }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.aar-toolbar {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px; margin-bottom: 16px;
}

.aar-search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--aa-white); border: 1.5px solid var(--aa-border);
  border-radius: 999px; padding: 8px 14px;
  flex: 1 1 160px; min-width: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  transition: border-color .15s, box-shadow .15s;
}
.aar-search-wrap:focus-within {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,.14);
}
.aar-search-wrap svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--aa-muted); }
.aar-search {
  border: none; outline: none; background: transparent;
  font-size: .88rem; width: 100%; min-width: 0; color: var(--aa-text);
}
.aar-search::placeholder { color: var(--aa-muted); }

.aar-filters { display: flex; flex-wrap: wrap; gap: 6px; }

.aar-filter {
  background: var(--aa-white); border: 1.5px solid var(--aa-border);
  border-radius: 999px; padding: 5px 12px;
  font-size: .79rem; font-weight: 600;
  color: var(--aa-muted); cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.aar-filter:hover { border-color: #94a3b8; color: var(--aa-text); }
.aar-filter.is-active { background: #1e293b; border-color: #1e293b; color: #fff; }
.aar-filter[data-f]:not([data-f="all"]).is-active {
  background: var(--fb); border-color: var(--fc); color: var(--fc);
}

/* ── Card Grid ───────────────────────────────────────────────────────────── */
.aar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* Staggered fade-up entrance */
@media (prefers-reduced-motion: no-preference) {
  .aar-card {
    animation: aarUp .32s ease both;
    animation-delay: calc(var(--ci, 0) * 35ms);
  }
  @keyframes aarUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
  }
}

.aar-card {
  background: var(--aa-white);
  border-radius: var(--aa-radius);
  box-shadow: var(--aa-shadow);
  border-top: 4px solid var(--cc, #6366f1);
  display: flex; flex-direction: column;
  transition: box-shadow .2s, transform .2s;
  overflow: hidden;
}
.aar-card:hover {
  box-shadow: var(--aa-shadow-h);
  transform: translateY(-2px);
}
.aar-card[hidden] { display: none !important; }

/* Card head */
.aar-card__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; padding: 14px 14px 0;
}
.aar-card__name {
  font-size: .88rem; font-weight: 700; line-height: 1.35;
  color: var(--aa-text);
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* Card body: ring + stats */
.aar-card__body {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  flex: 1;
}

/* ── SVG Ring ────────────────────────────────────────────────────────────── */
.aar-ring {
  position: relative; flex-shrink: 0;
  width: 76px; height: 76px; margin: 0;
}
.aar-ring svg { width: 100%; height: 100%; display: block; }
.aar-ring__bg  { fill: none; stroke: #e2e8f0; stroke-width: 7; }
.aar-ring__arc { fill: none; stroke-width: 7; stroke-linecap: round; }
.aar-ring__cap {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}
.aar-ring__val { font-size: .78rem; font-weight: 800; line-height: 1; color: var(--aa-text); }
.aar-ring__lbl {
  font-size: .59rem; font-weight: 600; color: var(--aa-muted);
  text-transform: uppercase; letter-spacing: .04em;
}

/* ── Stats 2×2 grid ──────────────────────────────────────────────────────── */
.aar-stats {
  flex: 1; min-width: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px;
  margin: 0;
}
.aar-stat { display: flex; flex-direction: column; gap: 1px; }
.aar-stat dt {
  font-size: .64rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--aa-muted); white-space: nowrap;
}
.aar-stat dd {
  font-size: .93rem; font-weight: 800; margin: 0;
  color: var(--aa-text); white-space: nowrap;
}
.aar-stat--cor dd { color: #10b981; }
.aar-stat--inc dd { color: #ef4444; }

/* ── Correct/Incorrect split bar (question report) ───────────────────────── */
.aar-split { padding: 0 14px 10px; }
.aar-split__bar {
  display: flex; height: 7px;
  border-radius: 999px; overflow: hidden;
  background: #f1f5f9;
}
.aar-split__cor { background: #10b981; }
.aar-split__inc { background: #ef4444; }
.aar-split__leg {
  display: flex; justify-content: space-between;
  margin-top: 5px;
}
.aar-split__lc { font-size: .72rem; font-weight: 700; color: #059669; }
.aar-split__li { font-size: .72rem; font-weight: 700; color: #dc2626; }

/* ── Card footer: vs-class bar + rank ───────────────────────────────────── */
.aar-card__foot {
  border-top: 1px solid var(--aa-border);
  padding: 10px 14px 12px;
  display: flex; flex-direction: column; gap: 8px;
  margin-top: auto;
}

/* Comparison bar */
.aar-cbar__track {
  position: relative; height: 8px;
  background: #e2e8f0; border-radius: 999px; overflow: visible;
  margin-bottom: 2px;
}
.aar-cbar__fill {
  height: 100%; border-radius: 999px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
  position: absolute; left: 0; top: 0;
}
/* Triangle pins above the track */
.aar-cbar__pin {
  position: absolute; top: 50%; transform: translate(-50%,-50%);
  width: 2px; height: 16px; border-radius: 1px;
}
.aar-cbar__pin--avg { background: #64748b; }
.aar-cbar__pin--top { background: #f59e0b; }
.aar-cbar__pin--avg::before,
.aar-cbar__pin--top::before {
  content: ''; position: absolute; left: 50%; top: -5px;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-style: solid;
}
.aar-cbar__pin--avg::before { border-width: 0 4px 5px; border-color: transparent transparent #64748b; }
.aar-cbar__pin--top::before { border-width: 0 4px 5px; border-color: transparent transparent #f59e0b; }

.aar-cbar__leg {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px 8px; font-size: .7rem; font-weight: 600; color: var(--aa-muted);
}
.aar-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; vertical-align: middle; margin-right: 3px;
  flex-shrink: 0;
}
.aar-dot--avg { background: #64748b; }
.aar-dot--top { background: #f59e0b; }

.aar-delta {
  font-size: .73rem; font-weight: 700; padding: 2px 7px;
  border-radius: 999px; margin-left: auto;
}
.aar-delta--pos { background: #d1fae5; color: #065f46; }
.aar-delta--neg { background: #fee2e2; color: #991b1b; }

/* Rank row */
.aar-card__rank { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.aar-rank {
  font-size: .8rem; font-weight: 800;
  background: #ede9fe; color: #5b21b6;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.aar-rank em { font-style: normal; font-weight: 500; color: #7c3aed; opacity: .8; font-size: .74rem; }
.aar-pct {
  font-size: .73rem; font-weight: 600;
  background: #f0f9ff; color: #0369a1;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.aar-badge {
  display: inline-block; padding: 3px 9px; flex-shrink: 0;
  border-radius: 999px; font-size: .69rem; font-weight: 700; white-space: nowrap;
}
.aar-badge--excellent { background: #d1fae5; color: #065f46; }
.aar-badge--good      { background: #dbeafe; color: #1e40af; }
.aar-badge--average   { background: #fef3c7; color: #92400e; }
.aar-badge--weak      { background: #fee2e2; color: #991b1b; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.aar-empty {
  grid-column: 1 / -1;
  text-align: center; padding: 40px 20px;
  color: var(--aa-muted); font-size: .93rem;
}
.aar-empty[hidden] { display: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   BREAKPOINTS
═══════════════════════════════════════════════════════════════════════════ */

/* Tablet */
@media (max-width: 1024px) {
  .aar-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Large phone */
@media (max-width: 640px) {
  .aar-header__title { font-size: 1.2rem; }
  .aar-kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .aar-kpi__v { font-size: 1.35rem; }
  .aar-filter { font-size: .75rem; padding: 4px 10px; }
  .aar-ring { width: 68px; height: 68px; }
}

/* Phone — single column */
@media (max-width: 480px) {
  .aar-grid { grid-template-columns: 1fr; }
  .aar-toolbar { gap: 8px; }
  /* On 1-col, widen the ring so it's not tiny */
  .aar-ring { width: 72px; height: 72px; }
}

/* Very small */
@media (max-width: 360px) {
  .aar-kpis { grid-template-columns: 1fr 1fr; }
  .aar-card__body { gap: 10px; }
  .aar-stats { grid-template-columns: repeat(4, 1fr); }
  .aar-stat dt { font-size: .6rem; }
  .aar-stat dd { font-size: .82rem; }
}
