/* =====================================================================
   Application shells: admin, student, auth, public
   ===================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ---------------------------------------------------------------------
   Sidebar
   ------------------------------------------------------------------ */

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
  overflow: hidden;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.app-brand:hover { text-decoration: none; }
.app-brand__mark {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  font-weight: 750;
  font-size: var(--fs-sm);
  letter-spacing: -0.02em;
}
.app-brand__text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.app-brand__name { font-weight: 680; font-size: var(--fs-base); color: var(--text); letter-spacing: -0.01em; }
.app-brand__sub { font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-subtle); font-weight: 600; }

.app-nav { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-3) var(--sp-2) var(--sp-5); }
.app-nav__group { margin-bottom: var(--sp-4); }
.app-nav__title {
  padding: var(--sp-2) var(--sp-3) 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-subtle);
}
.app-nav__link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px var(--sp-3);
  margin-bottom: 1px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: var(--fs-base);
  font-weight: 500;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  position: relative;
}
.app-nav__link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.app-nav__link.is-active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
:root[data-theme="dark"] .app-nav__link.is-active,
:root[data-theme="contrast"] .app-nav__link.is-active { background: var(--surface-3); color: var(--brand-400); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .app-nav__link.is-active { background: var(--surface-3); color: var(--brand-400); }
}
.app-nav__link.is-active::before {
  content: "";
  position: absolute;
  left: -8px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--brand-600);
}
.app-nav__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-nav__badge {
  flex: 0 0 auto;
  min-width: 19px;
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.app-nav__badge--muted { background: var(--surface-3); color: var(--text-muted); }

.app-sidebar__foot { flex: 0 0 auto; padding: var(--sp-3); border-top: 1px solid var(--border); }

/* Collapsed rail */
.app.is-collapsed .app-brand__text,
.app.is-collapsed .app-nav__title,
.app.is-collapsed .app-nav__label,
.app.is-collapsed .app-nav__badge,
.app.is-collapsed .app-sidebar__foot .user-chip__text { display: none; }
.app.is-collapsed .app-nav__link { justify-content: center; padding-inline: 0; }
.app.is-collapsed .app-brand { justify-content: center; padding-inline: 0; }

/* ---------------------------------------------------------------------
   Main column
   ------------------------------------------------------------------ */

.app-main { display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-5);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.app-topbar__title { margin: 0; font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.012em; }
.app-topbar__sub { font-size: var(--fs-sm); color: var(--text-muted); }

.app-content { flex: 1 1 auto; padding: var(--sp-5); min-width: 0; }
.app-content--flush { padding: 0; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.page-head__title { margin: 0; font-size: var(--fs-2xl); letter-spacing: -0.02em; }
.page-head__desc { margin: var(--sp-1) 0 0; color: var(--text-muted); font-size: var(--fs-base); max-width: 72ch; }
.page-head__actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* Search box in the top bar */
.topsearch { position: relative; max-width: 380px; width: 100%; }
.topsearch .input { padding-left: 36px; background: var(--surface-3); border-color: transparent; }
.topsearch .input:focus { background: var(--surface); border-color: var(--brand-500); }
.topsearch > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); }

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 7px var(--sp-2);
  border: 0;
  border-radius: var(--r-md);
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.user-chip:hover { background: var(--surface-3); text-decoration: none; }
.user-chip__text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-chip__name { font-size: var(--fs-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip__role { font-size: var(--fs-xs); color: var(--text-muted); }

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.icon-btn__dot {
  position: absolute;
  top: 6px; right: 6px;
  min-width: 15px; height: 15px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}

/* ---------------------------------------------------------------------
   Mobile: sidebar becomes an off-canvas drawer
   ------------------------------------------------------------------ */

.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: var(--overlay);
  display: none;
}

@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app-sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--t-base) var(--ease);
    box-shadow: var(--sh-xl);
  }
  .app.is-drawer-open .app-sidebar { transform: none; }
  .app.is-drawer-open .sidebar-scrim { display: block; }
  .app-content { padding: var(--sp-4); }
  .app-topbar { padding-inline: var(--sp-4); }
}

/* ---------------------------------------------------------------------
   Student shell: top navigation instead of a sidebar
   ------------------------------------------------------------------ */

.stu-shell { min-height: 100vh; display: flex; flex-direction: column; }

.stu-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.stu-header__bar { display: flex; align-items: center; gap: var(--sp-4); height: 62px; }
.stu-nav { display: flex; align-items: center; gap: 2px; }
.stu-nav__link {
  padding: 7px 12px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: var(--fs-base);
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.stu-nav__link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.stu-nav__link.is-active { color: var(--brand-700); background: var(--brand-50); }
:root[data-theme="dark"] .stu-nav__link.is-active { background: var(--surface-3); color: var(--brand-400); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stu-nav__link.is-active { background: var(--surface-3); color: var(--brand-400); }
}

.stu-main { flex: 1 1 auto; padding: var(--sp-6) 0 var(--sp-9); }

.stu-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: var(--sp-6) 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.stu-footer a { color: var(--text-muted); }
.stu-footer a:hover { color: var(--brand-600); }

/* Bottom tab bar on phones — mirrors the mobile app's information
   architecture so the two products feel like one. */
.stu-tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 45;
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.stu-tabbar__item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 2px 6px;
  color: var(--text-subtle);
  font-size: 10px;
  font-weight: 600;
}
.stu-tabbar__item.is-active { color: var(--brand-600); }
.stu-tabbar__item:hover { text-decoration: none; }

@media (max-width: 860px) {
  .stu-nav { display: none; }
  .stu-tabbar { display: flex; }
  .stu-main { padding-bottom: 84px; }
  .stu-footer { display: none; }
}

/* ---------------------------------------------------------------------
   Auth pages
   ------------------------------------------------------------------ */

.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth__aside {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--sp-10) var(--sp-9);
  background: linear-gradient(150deg, var(--brand-700) 0%, var(--brand-900) 55%, #131a4d 100%);
  color: #fff;
  overflow: hidden;
}
.auth__aside::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,0.14), transparent 42%),
    radial-gradient(circle at 82% 78%, rgba(255,255,255,0.10), transparent 46%);
  pointer-events: none;
}
.auth__aside > * { position: relative; z-index: 1; }
.auth__aside h1 { color: #fff; font-size: var(--fs-3xl); max-width: 15ch; }
.auth__aside p { color: rgba(255,255,255,0.82); font-size: var(--fs-lg); max-width: 42ch; }
.auth__points { list-style: none; padding: 0; margin: var(--sp-7) 0 0; display: grid; gap: var(--sp-3); }
.auth__points li { display: flex; align-items: flex-start; gap: var(--sp-3); color: rgba(255,255,255,0.9); margin: 0; }
.auth__points svg { flex: 0 0 auto; margin-top: 2px; color: #a5f3d0; }

.auth__panel { display: flex; align-items: center; justify-content: center; padding: var(--sp-7) var(--sp-5); background: var(--bg); }
.auth__box { width: 100%; max-width: 400px; }
.auth__logo { display: inline-flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); }

@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth__aside { display: none; }
}

/* ---------------------------------------------------------------------
   Public landing
   ------------------------------------------------------------------ */

.hero {
  padding: var(--sp-10) 0 var(--sp-9);
  background:
    radial-gradient(1100px 460px at 50% -12%, color-mix(in srgb, var(--brand-500) 15%, transparent), transparent),
    var(--bg);
  text-align: center;
}
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 3rem); letter-spacing: -0.028em; max-width: 20ch; margin-inline: auto; }
.hero p { max-width: 60ch; margin: var(--sp-4) auto var(--sp-6); font-size: var(--fs-lg); color: var(--text-muted); }
.hero__actions { display: flex; gap: var(--sp-3); justify-content: center; flex-wrap: wrap; }

.exam-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
  position: relative;
  overflow: hidden;
}
.exam-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--exam-color, var(--brand-500));
}
.exam-card:hover { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--border-strong); text-decoration: none; }
.exam-card__mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--exam-color, var(--brand-500)) 13%, transparent);
  color: var(--exam-color, var(--brand-500));
  font-weight: 700;
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-2);
}
.exam-card__name { font-size: var(--fs-md); font-weight: 650; color: var(--text); }
.exam-card__meta { font-size: var(--fs-sm); color: var(--text-muted); }
.exam-card__stats { display: flex; gap: var(--sp-4); margin-top: auto; padding-top: var(--sp-3); font-size: var(--fs-sm); color: var(--text-muted); }

.section-head { text-align: center; margin-bottom: var(--sp-7); }
.section-head h2 { font-size: var(--fs-2xl); letter-spacing: -0.02em; }
.section-head p { color: var(--text-muted); max-width: 62ch; margin-inline: auto; }

.feature { padding: var(--sp-5); }
.feature__icon {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--brand-50);
  color: var(--brand-600);
  margin-bottom: var(--sp-3);
}
:root[data-theme="dark"] .feature__icon { background: var(--surface-3); }
