/* ===========================================================================
   Progress Workspace — BENTO MASTERY DASHBOARD + slide-in drawer.

   Surface: an overall-mastery hero + a responsive bento grid of subject cards
   (the weakest started subject promoted to a wide "focus" card). Selecting a
   subject slides a drawer in over a scrim; the drawer holds the subject's ring
   and its topics as an accordion that reveals subtopics inline.

   Net-new + isolated. ALL selectors use the `pw-` prefix (no qw- / app- /
   legacy collision). Reuses the shared brand tokens defined on .app-shell in
   app_shell.css — NO :root re-definition here.
   =========================================================================== */

/* Single-scrollbar layout. The shared shell hardcodes height: calc(100vh - 60px)
   assuming a 60px navbar; any deviation makes navbar + shell overflow the viewport,
   so the WINDOW scrolls AS WELL AS the dashboard (the two scrollbars). Rather than
   trust that magic number, make the body a full-height flex column with NO window
   scroll, and let the shell flex to fill whatever height the navbar leaves. The
   dashboard (.pw-dash) is then the only scroll container. */
body.pw-page { margin: 0; height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
body.pw-page > #pw-app.app-shell { flex: 1 1 auto; height: auto; min-height: 0; }

/* ---------- fill the shell content region; the dash owns the scroll ---------- */
.app-content.pw-fill { padding: 0; overflow: hidden; display: flex; }
.app-content__wrap.pw-wrap {
  max-width: none; margin: 0; width: 100%; min-width: 0;
  flex: 1; display: flex; position: relative; overflow: hidden;
}
.pw-dash { flex: 1; min-width: 0; overflow-y: auto; padding: 24px 28px 48px; }

/* ---------- shared buttons ---------- */
.pw-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 11px;
  font-weight: 600; font-size: 13.5px; text-decoration: none;
  border: none; cursor: pointer;
}
.pw-btn--primary { background: var(--brand-primary); color: #fff; }
.pw-btn--primary:hover { background: #4338ca; color: #fff; }
.pw-btn--soft { background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 7px 12px; }
.pw-btn--soft:hover { background: var(--brand-light); color: var(--brand-primary); }

.pw-hidden { display: none !important; }

/* ===========================================================================
   CONIC MASTERY RING — sized by class, coloured by --rc, filled by --p (0-100)
   =========================================================================== */
.pw-cring {
  --p: 0; --rc: var(--brand-primary); --sz: 56px; --ring: 6px;
  width: var(--sz); height: var(--sz); border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background:
    conic-gradient(var(--rc) calc(var(--p) * 1%), color-mix(in srgb, var(--rc) 16%, var(--line)) 0);
  transition: background .5s ease;
}
.pw-cring i {
  width: calc(var(--sz) - var(--ring) * 2); height: calc(var(--sz) - var(--ring) * 2);
  border-radius: 50%; background: var(--card);
  display: grid; place-items: center;
  font-style: normal; font-weight: 800; color: var(--ink);
  font-size: calc(var(--sz) * .26); font-variant-numeric: tabular-nums; line-height: 1;
}
.pw-cring i span { font-size: .62em; font-weight: 700; color: var(--muted); margin-left: 1px; }
.pw-cring--sm { --sz: 38px; --ring: 5px; }
.pw-cring--lg { --sz: 68px; --ring: 7px; }
.pw-cring--xl { --sz: 104px; --ring: 10px; }

/* ===========================================================================
   HERO — overall mastery
   =========================================================================== */
.pw-hero {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--brand-primary) 14%, var(--card)) 0%, var(--card) 52%);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 26px; margin-bottom: 22px;
}
.pw-hero__ring { flex: none; }
.pw-hero__body { flex: 1; min-width: 200px; }
.pw-hero__title { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); }
.pw-hero__sub { margin: 3px 0 12px; color: var(--muted); font-size: 13.5px; }

.pw-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pw-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; color: var(--muted);
}
.pw-chip b { color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.pw-chip--focus {
  background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, var(--line));
  color: var(--warn); font-weight: 700;
}

.pw-hero__search {
  display: flex; align-items: center; gap: 8px; align-self: stretch;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 13px; color: var(--muted); font-size: 13px; min-width: 200px;
}
.pw-hero__search input { border: none; outline: none; background: none; flex: 1; font-family: inherit; font-size: 13.5px; color: var(--ink); }

/* admin strip (validation + source PDF) sits between hero and grid */
.pw-adminstrip { margin-bottom: 18px; }

/* ===========================================================================
   BENTO GRID OF SUBJECT CARDS
   =========================================================================== */
.pw-bento {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  grid-auto-rows: 1fr;
  gap: 16px;
}
.pw-card {
  display: flex; flex-direction: column; gap: 14px;
  text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; cursor: pointer; color: var(--ink);
  position: relative; overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.pw-card::after {                       /* thin brand top edge that grows on hover */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand-primary), var(--brand-secondary));
  transform: scaleX(0); transform-origin: left; transition: transform .2s ease;
}
.pw-card:hover { transform: translateY(-3px); box-shadow: 0 8px 26px rgba(15, 23, 42, .12); border-color: color-mix(in srgb, var(--brand-primary) 30%, var(--line)); }
.pw-card:hover::after { transform: scaleX(1); }
.pw-card:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.pw-card--active { border-color: var(--brand-primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-primary) 30%, transparent), var(--shadow); }
.pw-card--muted { opacity: .72; }

/* the weakest started subject — a wide focus tile */
.pw-card--feature { grid-column: span 2; background: radial-gradient(130% 120% at 100% 0%, color-mix(in srgb, var(--brand-secondary) 12%, var(--card)) 0%, var(--card) 55%); }
.pw-card--feature .pw-card__ring { align-self: flex-start; }

.pw-card__head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pw-card__name { font-weight: 700; font-size: 15px; line-height: 1.25; overflow-wrap: break-word; min-width: 0; }
.pw-card__ring { display: flex; justify-content: center; padding: 2px 0; }
.pw-card__foot { margin-top: auto; display: flex; flex-direction: column; gap: 9px; }
.pw-card__foot small { color: var(--muted); font-size: 12px; }
.pw-card__badge {
  align-self: flex-start; font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; background: var(--bg); color: var(--muted);
}
.pw-card__badge--new { background: var(--brand-light); color: var(--brand-primary); }

/* mastery-band distribution bar (real: needs / improving / strong topic counts) */
.pw-bands { display: flex; height: 7px; border-radius: 999px; overflow: hidden; background: var(--line); }
.pw-bands i { display: block; height: 100%; }

/* leading subject-icon tile (reused look from subjects_page) */
.pw-sicon {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; font-size: 17px; line-height: 1;
  background: rgba(79, 70, 229, .08);
}
.pw-sicon i { font-size: 15px; color: var(--brand-primary); }

/* ===========================================================================
   SCRIM + DRAWER
   =========================================================================== */
.pw-scrim {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(15, 23, 42, .40); backdrop-filter: blur(1.5px);
  opacity: 0; transition: opacity .26s ease;
}
.pw-scrim.pw-open { opacity: 1; }

.pw-drawer {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(580px, 94%);
  background: var(--card); border-left: 1px solid var(--line);
  box-shadow: -18px 0 48px rgba(15, 23, 42, .18);
  display: flex; flex-direction: column; min-height: 0;
  transform: translateX(100%); transition: transform .28s cubic-bezier(.22, .61, .36, 1);
  will-change: transform;
}
.pw-drawer.pw-open { transform: translateX(0); }

.pw-dhead {
  flex: none; padding: 18px 22px 16px; border-bottom: 1px solid var(--line);
  background:
    radial-gradient(120% 160% at 100% 0%, color-mix(in srgb, var(--brand-primary) 12%, var(--card)) 0%, var(--card) 60%);
}
.pw-dclose {
  position: absolute; top: 14px; right: 16px;
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px; color: var(--muted);
  background: var(--card); border: 1px solid var(--line) !important; cursor: pointer;
}
.pw-dclose:hover { background: var(--bg); color: var(--ink); }
.pw-dhead__main { display: flex; align-items: center; gap: 14px; padding-right: 40px; }
.pw-dhead__main .pw-sicon { width: 40px; height: 40px; font-size: 22px; border-radius: 12px; }
.pw-dhead__main .pw-sicon i { font-size: 19px; }
.pw-dhead__txt { flex: 1; min-width: 0; }
.pw-dhead__title { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: break-word; }
.pw-dhead__m { color: var(--muted); font-size: 13px; margin-top: 3px; }
.pw-dhead .pw-cring { margin-left: auto; }

.pw-dbody { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 18px 26px; }

/* drawer search + relevance line */
.pw-srch {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 11px;
  padding: 8px 12px; color: var(--muted); font-size: 13px;
}
.pw-srch input { border: none; outline: none; background: none; flex: 1; font-family: inherit; font-size: 13.5px; color: var(--ink); }
.pw-drel { font-size: 12px; color: var(--muted); padding: 0 4px 8px; }

/* topic accordion */
.pw-tlist { display: flex; flex-direction: column; gap: 8px; }
.pw-titem { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: var(--card); transition: border-color .15s ease, box-shadow .15s ease; }
.pw-titem--open { border-color: color-mix(in srgb, var(--brand-primary) 35%, var(--line)); box-shadow: var(--shadow); }
.pw-trow { display: flex; align-items: center; gap: 12px; padding: 11px 13px; cursor: pointer; }
.pw-trow:hover { background: #f6f8fc; }
.pw-titem--open > .pw-trow { background: var(--brand-light); }
.pw-trow:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: -2px; }

.pw-tpanel { border-top: 1px dashed var(--line); padding: 6px 10px 12px; background: linear-gradient(180deg, #fbfcff, var(--card)); }

/* shared name / meta / practise bits (topics + subtopics) */
.pw-nm { flex: 1; font-weight: 600; font-size: 14px; min-width: 0; line-height: 1.3; overflow-wrap: break-word; }
.pw-nm small { display: block; color: var(--muted); font-weight: 500; font-size: 11.5px; line-height: 1.3; }
.pw-pc { width: 42px; text-align: right; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.pw-chev { color: var(--muted); font-size: 16px; flex: none; }
.pw-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 6px; }
.pw-mini { width: 56px; height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; flex: none; }
.pw-mini--wide { width: 76px; }
.pw-mini i { display: block; height: 100%; border-radius: 99px; }
.pw-prac {
  flex: none; background: var(--brand-light); color: var(--brand-primary);
  border-radius: 8px; padding: 6px 11px; font-weight: 700; font-size: 12px;
  text-decoration: none; white-space: nowrap;
}
.pw-prac:hover { background: var(--brand-primary); color: #fff; }

/* subtopic rows inside an open topic panel */
.pw-srow { display: flex; align-items: flex-start; gap: 11px; padding: 9px 8px; border-radius: 10px; }
.pw-srow:hover { background: #fafbff; }

.pw-showall {
  display: block; width: 100%; text-align: center; padding: 10px; margin-top: 4px;
  color: var(--brand-primary); font-weight: 700; font-size: 13px;
  border-radius: 10px; background: none; border: none; cursor: pointer;
}
.pw-showall:hover { background: var(--brand-light); }

.pw-subloading { padding: 4px 0; }
.pw-subempty {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg); border: 1px dashed var(--line); border-radius: 12px;
  padding: 14px 16px; font-size: 13px; color: var(--muted);
}

/* ===========================================================================
   SKELETONS + SPINNER (reused)
   =========================================================================== */
.pw-skelrow { display: flex; align-items: center; gap: 11px; padding: 11px 8px; }
.pw-skel-ic { width: 26px; height: 26px; border-radius: 8px; flex: none; }
.pw-skel-l { height: 9px; border-radius: 6px; display: inline-block; }
.pw-skel-bar { width: 54px; height: 6px; border-radius: 99px; flex: none; }
.pw-skel-ic, .pw-skel-l, .pw-skel-bar, .pw-thero--skel {
  background: linear-gradient(100deg, #e6eaf3 28%, #f3f6fc 48%, #e6eaf3 68%);
  background-size: 220% 100%;
  animation: pw-shimmer 1.25s ease-in-out infinite;
}
.pw-cring.pw-thero--skel { border-radius: 50%; }
@keyframes pw-shimmer { 0% { background-position: 220% 0; } 100% { background-position: -120% 0; } }

.pw-card--skel { cursor: default; pointer-events: none; }
.pw-card--skel:hover { transform: none; box-shadow: var(--shadow); }

.pw-loadblock { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 13px; padding: 52px 24px; text-align: center; }
.pw-spin {
  width: 46px; height: 46px; border-radius: 50%;
  background: conic-gradient(from 90deg, var(--brand-primary), var(--brand-secondary) 60%, rgba(124, 58, 237, 0) 92%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  animation: pw-rotate .85s linear infinite;
}
@keyframes pw-rotate { to { transform: rotate(360deg); } }
.pw-loadblock__t { font-size: 14px; font-weight: 700; color: var(--ink); }
.pw-loadblock__s { font-size: 12.5px; color: var(--muted); margin-top: -5px; }

/* ===========================================================================
   ADMIN controls (validation segmented + source PDF)
   =========================================================================== */
.pw-admin { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pw-seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pw-seg__btn { padding: 6px 13px; font-size: 12.5px; font-weight: 700; color: var(--muted); background: transparent; border: none; cursor: pointer; }
.pw-seg__btn.on { background: var(--brand-primary); color: #fff; }
.pw-pdf { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.pw-pdf__select {
  padding: 6px 11px; border-radius: 9px; border: 1px solid var(--line);
  font-size: 13px; min-width: 200px; max-width: 260px; background: var(--card); color: var(--ink);
}

/* Source PDF filter inside the drawer header — own line, full-width select */
.pw-dpdf { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.pw-dpdf .pw-pdf__label { flex: none; }
.pw-dpdf .pw-pdf__select { flex: 1; min-width: 0; max-width: none; }

/* ===========================================================================
   Terminal states (drawer detail + whole page)
   =========================================================================== */
.pw-detail-state { max-width: 420px; margin: 40px auto; text-align: center; padding: 12px; }
.pw-detail-state__icon { font-size: 40px; line-height: 1; margin-bottom: 12px; }
.pw-detail-state h3 { font-size: 18px; margin: 0 0 8px; color: var(--ink); }
.pw-detail-state p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.pw-detail-state__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.pw-state {
  max-width: 520px; margin: 56px auto; text-align: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px 32px;
}
.pw-state__icon { font-size: 44px; line-height: 1; margin-bottom: 14px; }
.pw-state__title { font-size: 20px; margin: 0 0 8px; color: var(--ink); }
.pw-state__msg { color: var(--muted); font-size: 14.5px; margin: 0 0 22px; }
.pw-state__cta {
  display: inline-block; background: var(--brand-primary); color: #fff;
  text-decoration: none; font-weight: 600; font-size: 14px; padding: 11px 20px; border-radius: 11px;
}
.pw-state__cta:hover { background: #4338ca; color: #fff; }

/* ===========================================================================
   RESPONSIVE
   =========================================================================== */
@media (max-width: 760px) {
  .pw-dash { padding: 16px 16px 40px; }
  .pw-hero { padding: 18px; gap: 16px; }
  .pw-hero__search { order: 3; width: 100%; }
  .pw-bento { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .pw-card--feature { grid-column: span 2; }
  .pw-drawer { width: 100%; border-left: none; }
}

@media (prefers-reduced-motion: reduce) {
  .pw-skel-ic, .pw-skel-l, .pw-skel-bar, .pw-thero--skel { animation: none; }
  .pw-spin { animation-duration: 2.4s; }
  .pw-drawer, .pw-scrim, .pw-card, .pw-card::after, .pw-cring { transition: none; }
}
