/* =========================================================================
   Appmarq UI — replaces Bootstrap 3 on migrated pages.
   Based on the CAST Design System V2 (neutrals, Roboto, flat cards)
   with #5C29EB as the primary colour.
   No framework, no build step. Components are prefixed "am-".
   ========================================================================= */

/* ---------- Fonts (self-hosted) ---------- */
@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/roboto/roboto-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/roboto/roboto-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/roboto/roboto-latin-700-normal.woff2') format('woff2'); }

/* ---------- Tokens ---------- */
:root {
  --am-primary: #5C29EB;
  --am-primary-hover: #4B1FCB;
  --am-primary-active: #3C18A6;
  --am-primary-tint: #F1ECFE;

  --am-text: #191716;
  --am-text-2: #454D54;
  --am-text-3: #5C6670;
  --am-text-inverse: #FFFFFF;

  --am-bg: #FFFFFF;
  --am-bg-1: #FAFAFA;
  --am-bg-2: #F5F5F5;
  --am-ink: #191716;          /* dark header / bands */

  --am-line: #E3E6E8;
  --am-line-2: #C7CCD1;

  --am-success-text: #006828; --am-success-bg: #E3FFEE;
  --am-warning-text: #7A4F00; --am-warning-bg: #FEF2DB;
  --am-error-text:   #811725; --am-error-bg:   #FFE9E9;
  --am-teal: #388188;

  --am-radius: 6px;
  --am-radius-card: 8px;
  --am-radius-lg: 12px;
  --am-pill: 250px;

  --am-shadow-sm: 0 2px 4px rgba(21,21,21,.08);
  --am-shadow-lg: 0 8px 24px rgba(21,21,21,.16);

  --am-font: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --am-max: 1200px;
}

/* ---------- Base ---------- */
.am, .am * , .am *::before, .am *::after { box-sizing: border-box; }
body.am {
  margin: 0;
  font-family: var(--am-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--am-text);
  background: var(--am-bg);
  -webkit-font-smoothing: antialiased;
}
.am h1, .am h2, .am h3, .am h4 { margin: 0; font-weight: 700; line-height: 1.2; color: var(--am-text); }
.am p { margin: 0; }
.am a { color: var(--am-primary); text-decoration: none; }
.am a:hover { color: var(--am-primary-active); text-decoration: underline; }
.am img { max-width: 100%; }
.am :where(a, button, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--am-primary);
  outline-offset: 2px;
}
.am-visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.am-muted { color: var(--am-text-3); }
.am-lead { font-size: 17px; line-height: 1.55; color: var(--am-text-2); }

/* ---------- Layout ---------- */
.am-container { max-width: var(--am-max); margin: 0 auto; padding-left: 24px; padding-right: 24px; }
.am-section { padding-top: 72px; padding-bottom: 72px; }
.am-section--tinted { background: var(--am-bg-1); border-top: 1px solid var(--am-line); border-bottom: 1px solid var(--am-line); }
.am-section-head { display: flex; flex-direction: column; gap: 12px; max-width: 760px; margin-bottom: 40px; }
.am-section-head h2 { font-size: 36px; }
.am-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(var(--am-min, 280px), 1fr)); }
.am-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.am-stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Brand ---------- */
.am-brand { display: inline-flex; align-items: center; gap: 12px; color: var(--am-text); text-decoration: none; }
.am a.am-brand, .am a.am-brand:hover { text-decoration: none; color: var(--am-text); }
.am a.am-brand--on-dark, .am a.am-brand--on-dark:hover { color: var(--am-text-inverse); }
.am-brand img { display: block; height: 40px; width: auto; }
.am-brand__divider { width: 1px; height: 22px; background: var(--am-line-2); }
.am-brand__name { font-size: 18px; font-weight: 500; }
.am-brand--dark-logo img { filter: brightness(0); }     /* white logo shown black on light grounds */
.am-brand--on-dark { color: var(--am-text-inverse); }
.am-brand--on-dark .am-brand__divider { background: #5C6670; }

/* ---------- Site header (public pages) ---------- */
.am-topbar { position: sticky; top: 0; z-index: 50; background: var(--am-bg); border-bottom: 1px solid var(--am-line); }
.am-topbar__inner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 32px; padding-top: 12px; padding-bottom: 12px; }
.am-topbar__nav { display: flex; flex-wrap: wrap; gap: 0 24px; flex: 1 1 auto; }
.am .am-topbar__nav a { color: var(--am-text-2); font-weight: 500; padding: 10px 0; }
.am .am-topbar__nav a:hover { color: var(--am-text); text-decoration: none; }
.am-topbar__actions { display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.am-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--am-radius);
  font: 500 15px/1.2 var(--am-font); text-decoration: none; cursor: pointer;
  transition: background-color .14s ease-out, border-color .14s ease-out, color .14s ease-out;
  white-space: nowrap;
}
.am a.am-btn:hover { text-decoration: none; }
.am-btn--primary { background: var(--am-primary); color: #FFFFFF; }
.am .am-btn--primary, .am .am-btn--primary:hover { color: #FFFFFF; }
.am-btn--primary:hover { background: var(--am-primary-hover); }
.am-btn--primary:active { background: var(--am-primary-active); }
.am-btn--secondary { background: var(--am-bg); color: var(--am-text); border-color: var(--am-line-2); }
.am .am-btn--secondary, .am .am-btn--secondary:hover { color: var(--am-text); }
.am-btn--secondary:hover { background: var(--am-primary-tint); border-color: var(--am-primary); }
.am-btn--ghost { background: transparent; color: var(--am-text-3); }
.am-btn--ghost:hover { background: var(--am-bg-2); color: var(--am-text); }
.am-btn--lg { min-height: 48px; padding: 0 24px; font-size: 16px; }
.am-btn--block { width: 100%; }
.am-btn--icon { width: 44px; padding: 0; }
.am-btn[disabled], .am-btn[aria-disabled="true"] { opacity: .3; cursor: not-allowed; pointer-events: none; }
.am-btn svg { flex: none; }

/* ---------- Chips ---------- */
.am-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--am-pill); font-size: 12px; font-weight: 500; line-height: 1.4; background: var(--am-bg-2); color: var(--am-text-2); }
.am-chip--primary { background: var(--am-primary-tint); color: var(--am-primary-active); }
.am-chip--success { background: var(--am-success-bg); color: var(--am-success-text); }
.am-chip--warning { background: var(--am-warning-bg); color: var(--am-warning-text); }
.am-chip--error   { background: var(--am-error-bg); color: var(--am-error-text); }

/* ---------- Cards ---------- */
.am-card { background: var(--am-bg); border: 1px solid var(--am-line); border-radius: var(--am-radius-card); padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.am-card h3 { font-size: 19px; }
.am-card p { color: var(--am-text-2); line-height: 1.55; }
.am-card--raised { box-shadow: var(--am-shadow-lg); border-radius: var(--am-radius-lg); }
.am-card--flush { padding: 0; gap: 0; }
.am-card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--am-line); }
.am-card__head h2 { font-size: 16px; }
.am-card__body { padding: 20px; }
.am .am-card--link { color: var(--am-text); text-decoration: none; }
.am .am-card--link:hover { border-color: var(--am-primary); text-decoration: none; color: var(--am-text); }
.am-icon-tile { width: 40px; height: 40px; border-radius: var(--am-radius-card); background: var(--am-primary-tint); color: var(--am-primary); display: flex; align-items: center; justify-content: center; flex: none; }

.am-stat { display: flex; flex-direction: column; gap: 4px; }
.am-stat__value { font-size: 36px; font-weight: 700; color: var(--am-primary); line-height: 1.15; }
.am-stat__label { font-weight: 500; }
.am-stat--compact { padding: 18px; }
.am-stat--compact .am-stat__label { order: -1; font-size: 13px; font-weight: 400; color: var(--am-text-3); }
.am-stat--compact .am-stat__value { font-size: 26px; color: var(--am-text); }

/* ---------- Bars (hero sample) ---------- */
.am-bar { height: 10px; border-radius: var(--am-pill); background: var(--am-bg-2); overflow: hidden; }
.am-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--am-primary); }

/* ---------- Forms ---------- */
.am-form { display: flex; flex-direction: column; gap: 16px; }
.am-field { display: flex; flex-direction: column; gap: 6px; }
.am-field__row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.am-field label { font-size: 13px; font-weight: 500; color: var(--am-text-2); }
.am-input {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--am-line-2); border-radius: var(--am-radius);
  background: var(--am-bg); color: var(--am-text);
  font: 400 15px/1.3 var(--am-font);
  transition: border-color .14s ease-out, box-shadow .14s ease-out;
}
.am-input:hover { border-color: #8F99A3; }
.am-input:focus { outline: none; border-color: var(--am-primary); box-shadow: 0 0 0 1px var(--am-primary); }
.am-input[aria-invalid="true"] { border-color: #D7263D; box-shadow: 0 0 0 1px #D7263D; }
.am-help { font-size: 13px; color: var(--am-text-3); }
.am-form__grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ---------- Alerts / banners ---------- */
.am-alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--am-radius-card); font-size: 14px; line-height: 1.45; }
.am-alert[hidden] { display: none; }
.am-alert svg { flex: none; margin-top: 1px; }
.am-alert--error { background: var(--am-error-bg); color: var(--am-error-text); }
.am-alert--warning { background: var(--am-warning-bg); color: var(--am-warning-text); }
.am-alert--success { background: var(--am-success-bg); color: var(--am-success-text); }
.am-alert--info { background: var(--am-bg); border: 1px solid var(--am-line); color: var(--am-text-2); align-items: center; flex-wrap: wrap; }

/* ---------- Dialog (native <dialog>) ---------- */
.am-dialog {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: 0; border-radius: var(--am-radius-lg);
  background: var(--am-bg); color: var(--am-text); box-shadow: var(--am-shadow-lg);
  overflow: auto;
}
.am-dialog--wide { width: min(560px, calc(100vw - 32px)); }
.am-dialog::backdrop { background: rgba(25,23,22,.48); }
.am-dialog__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 24px 0; }
.am-dialog__head h2 { font-size: 22px; }
.am-dialog__head p { margin-top: 6px; font-size: 14px; color: var(--am-text-3); }
.am-dialog__close { margin: -10px -10px 0 0; font-size: 22px; line-height: 1; }
.am-dialog__body { padding: 24px; }
.am-dialog__foot { border-top: 1px solid var(--am-line); padding: 16px 24px; font-size: 14px; color: var(--am-text-3); text-align: center; }
.am-busy { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 24px 0 8px; color: var(--am-text-2); }
.am-busy[hidden] { display: none; }
.am-spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--am-primary-tint); border-top-color: var(--am-primary); animation: am-spin .8s linear infinite; }
@keyframes am-spin { to { transform: rotate(360deg); } }

/* ---------- Tables ---------- */
.am-table-wrap { overflow-x: auto; position: relative; }
.am-table { width: 100%; min-width: 600px; border-collapse: collapse; font-size: 14px; }
.am-table th { padding: 10px 20px; background: var(--am-bg-1); color: var(--am-text-3); font-size: 13px; font-weight: 500; text-align: left; }
.am-table td { padding: 12px 20px; border-top: 1px solid var(--am-line); color: var(--am-text-2); vertical-align: middle; white-space: nowrap; }
.am-table th { white-space: nowrap; }
.am-table td.am-wrap { white-space: normal; }
.am-table tbody tr:hover td { background: var(--am-bg-1); }
.am-table .am-num, .am-table .am-end { text-align: right; }
.am-table a.am-strong { font-weight: 500; }
.am-empty { padding: 32px 20px; text-align: center; color: var(--am-text-3); }

/* ---------- Dark band / footer ---------- */
.am-band { background: var(--am-ink); color: var(--am-text-inverse); border-radius: var(--am-radius-lg); padding: 48px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 24px; }
.am-band h2 { color: #FFFFFF; font-size: 30px; }
.am-band p { color: var(--am-line-2); }
.am-footer { border-top: 1px solid var(--am-line); font-size: 13px; color: var(--am-text-3); }
.am-footer__inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding-top: 28px; padding-bottom: 28px; }
.am .am-footer a { color: var(--am-text-3); }

/* ---------- Hero ---------- */
.am-hero { background: var(--am-bg-1); border-bottom: 1px solid var(--am-line); }
.am-hero__inner { display: flex; flex-wrap: wrap; align-items: center; gap: 56px; padding-top: 96px; padding-bottom: 88px; }
.am-hero__copy { flex: 1 1 480px; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.am-hero__copy h1 { font-size: clamp(36px, 5vw, 56px); line-height: 1.1; letter-spacing: -.5px; }
.am-hero__copy .am-lead { font-size: 19px; max-width: 560px; }
.am-hero__aside { flex: 1 1 420px; min-width: 0; }
.am-eyebrow { align-self: flex-start; font-size: 13px; font-weight: 500; color: var(--am-primary); background: var(--am-primary-tint); border-radius: var(--am-pill); padding: 6px 12px; }

/* ---------- App shell (signed-in pages) ---------- */
body.am-app { background: var(--am-bg-2); min-height: 100vh; display: flex; flex-direction: column; }
.am-appbar { background: var(--am-ink); color: #FFFFFF; position: sticky; top: 0; z-index: 50; }
.am-appbar__inner { min-height: 60px; padding: 0 24px; display: flex; align-items: center; gap: 16px; }
.am-appbar .am-brand img { height: 36px; }
.am-appbar__user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--am-line); }
.am-avatar { width: 34px; height: 34px; border-radius: var(--am-pill); background: var(--am-primary-tint); color: var(--am-primary); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; text-transform: uppercase; }
.am-menu-toggle { display: none; color: #FFFFFF; }
.am-menu-toggle:hover { background: #2E3338; color: #FFFFFF; }

.am-shell { flex: 1 1 auto; display: flex; align-items: stretch; }
.am-sidebar { width: 250px; flex: none; padding: 20px 12px; background: var(--am-bg); border-right: 1px solid var(--am-line); display: flex; flex-direction: column; gap: 2px; }
.am .am-sidebar a { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: var(--am-radius); color: var(--am-text-2); font-size: 14px; font-weight: 500; }
.am .am-sidebar a:hover { background: var(--am-bg-2); color: var(--am-text); text-decoration: none; }
.am .am-sidebar a[aria-current="page"] { background: var(--am-primary-tint); color: var(--am-primary); }
.am-sidebar svg { flex: none; }
.am-sidebar__sep { height: 1px; background: var(--am-line); margin: 10px 4px; }
.am-main { flex: 1 1 auto; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 24px; }
.am-page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.am-page-head h1 { font-size: 28px; }
.am-page-head p { margin-top: 4px; color: var(--am-text-3); }

@media (max-width: 860px) {
  .am-menu-toggle { display: inline-flex; }
  .am-sidebar { position: fixed; z-index: 40; top: 60px; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .16s ease-out; box-shadow: var(--am-shadow-lg); overflow-y: auto; }
  .am-shell.is-menu-open .am-sidebar { transform: none; }
  .am-main { padding: 20px 16px 40px; }
  .am-appbar__inner { padding: 0 12px; }
  .am-appbar__name { display: none; }
}
@media (max-width: 640px) {
  .am-section { padding-top: 48px; padding-bottom: 48px; }
  .am-hero__inner { padding-top: 56px; padding-bottom: 56px; gap: 32px; }
  .am-section-head h2 { font-size: 28px; }
  .am-band { padding: 28px; }
  .am-container { padding-left: 16px; padding-right: 16px; }
  .am-topbar__actions { width: 100%; }
  .am-topbar__actions .am-btn { flex: 1 1 0; }
}
@media (prefers-reduced-motion: reduce) {
  .am *, .am *::before, .am *::after { transition: none !important; animation-duration: 0s !important; }
}

/* =========================================================================
   Components added for the user pages
   ========================================================================= */

/* Two columns: side column + wide column, stacking on small screens */
.am-cols { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1100px) { .am-cols--side { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); } }

/* Search field with icon */
.am-search { position: relative; }
.am-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--am-text-3); pointer-events: none; }
.am-search .am-input { padding-left: 40px; }

/* Checkbox */
.am input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--am-primary); cursor: pointer; vertical-align: middle; }

/* Sticky bottom bar (selection actions) */
.am-actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: var(--am-ink); color: #FFFFFF; box-shadow: 0 -4px 16px rgba(21,21,21,.2); }
.am-actionbar[hidden] { display: none; }
.am-actionbar__inner { max-width: 1100px; margin: 0 auto; padding: 14px 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; }
body.am-app.has-actionbar .am-main { padding-bottom: 96px; }

/* File upload area */
.am-drop { border: 2px dashed var(--am-line-2); border-radius: var(--am-radius-card); padding: 24px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--am-text-2); transition: border-color .14s ease-out, background-color .14s ease-out; }
.am-drop.is-over { border-color: var(--am-primary); background: var(--am-primary-tint); }
.am-drop input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.am-upload-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.am-upload-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; background: var(--am-bg-1); border-radius: var(--am-radius); }
.am-upload-list .is-error { color: var(--am-error-text); }
.am-upload-list .is-done { color: var(--am-success-text); }

/* Video (16:9) */
.am-video { position: relative; aspect-ratio: 16 / 9; border-radius: var(--am-radius-card); overflow: hidden; background: var(--am-ink); }
.am-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Quartile badges (benchmark results) */
.am-q { display: inline-flex; min-width: 38px; justify-content: center; padding: 3px 8px; border-radius: var(--am-pill); font-size: 12px; font-weight: 700; color: #FFFFFF; }
.am-q--1 { background: #1F7A68; }
.am-q--2 { background: #9A6400; }
.am-q--3 { background: #C2412D; }
.am-q--4 { background: #B0002F; }
.am-q--na { background: #73808C; }

/* Dense table for wide data */
.am-table--dense { font-size: 13px; }
.am-table--dense th, .am-table--dense td { padding: 8px 12px; white-space: nowrap; }
.am-table--dense td.am-wrap { white-space: normal; min-width: 200px; }

/* Numbered steps (in dialogs) */
.am-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 20px; counter-reset: am-step; }
.am-steps li { display: grid; grid-template-columns: 32px 1fr; gap: 4px 14px; counter-increment: am-step; }
.am-steps li::before { content: counter(am-step); grid-row: span 3; width: 32px; height: 32px; border-radius: var(--am-pill); background: var(--am-primary-tint); color: var(--am-primary); font-weight: 700; display: flex; align-items: center; justify-content: center; }
.am-steps h3 { font-size: 15px; }
.am-steps p { font-size: 14px; color: var(--am-text-2); }
.am-steps .am-btn { justify-self: start; margin-top: 6px; }

/* Read-only value (token, codes) */
.am-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--am-bg-2); border-radius: var(--am-radius); padding: 10px 12px; word-break: break-all; color: var(--am-text); }

/* Resource list rows */
.am-list { list-style: none; margin: 0; padding: 0; }
.am-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--am-line); }
.am-list li:first-child { border-top: 0; }
.am-list__main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.am-file-type { font-size: 11px; font-weight: 700; letter-spacing: .4px; color: var(--am-text-2); background: var(--am-bg-2); border-radius: 4px; padding: 3px 6px; }
.am-table td.am-wrap { min-width: 160px; }
.am-list li.am-enroll { flex-direction: column; align-items: stretch; gap: 6px; padding: 12px 20px; }
.am-enroll__file { font-size: 14px; color: var(--am-text); overflow-wrap: anywhere; }
.am-enroll__meta { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--am-text-3); }
.am-table--compact th, .am-table--compact td { padding-left: 12px; padding-right: 12px; }
.am-table--compact th:first-child, .am-table--compact td:first-child { padding-left: 20px; width: 1%; }
.am-table--compact th:last-child, .am-table--compact td:last-child { padding-right: 16px; }
