/* app.css — Mobius Phoenix NLP certificate registry. Mobile-first. */
:root {
  --mp-purple:        #5b2bd9;
  --mp-purple-dark:   #3a1aa0;
  --mp-purple-light:  #b9a8ff;
  --mp-gold:          #d4af37;
  --mp-gold-dark:     #a8851c;
  --mp-bg:            #fafafa;
  --mp-surface:       #ffffff;
  --mp-text:          #1f1f2a;
  --mp-muted:         #6c6c80;
  --mp-border:        #e4e4ec;
  --mp-success:       #1f7a4f;
  --mp-warn:          #b25c00;
  --mp-error:         #b22222;
  --mp-info:          #2563a8;
  --radius:           10px;
  --shadow:           0 1px 3px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 15px;
  color: var(--mp-text);
  background: var(--mp-bg);
  line-height: 1.45;
}
a { color: var(--mp-purple); }
a:hover { color: var(--mp-purple-dark); }

/* ---- Topbar (mobile default) ---- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--mp-purple);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar .brand {
  color: #fff; text-decoration: none; font-weight: 600; font-size: 16px;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .who { font-size: 13px; color: #d8d0ff; }
.topbar .hamburger {
  background: transparent; color: #fff; border: none; cursor: pointer;
  font-size: 22px; padding: 0 8px; line-height: 1;
}
.topbar .is-btn { color: #fff; border-color: rgba(255,255,255,0.5); }
.topbar .is-btn-ghost:hover { background: rgba(255,255,255,0.15); }

/* ---- Off-canvas sidebar ---- */
.scrim { display: none; }
body.nav-open .scrim {
  display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 35;
}
.rnav {
  position: fixed; left: 0; top: 0; bottom: 0; width: 220px;
  background: var(--mp-surface); border-right: 1px solid var(--mp-border);
  padding: 70px 14px 14px; z-index: 36;
  transform: translateX(-100%); transition: transform 0.18s ease;
  display: flex; flex-direction: column; gap: 4px;
}
body.nav-open .rnav { transform: translateX(0); }
.rnav a {
  display: block; padding: 10px 12px; border-radius: 8px;
  color: var(--mp-text); text-decoration: none; font-size: 14px;
}
.rnav a:hover { background: #f0eaff; }
.rnav a.is-active { background: var(--mp-purple); color: #fff; }
.rnav hr { border: none; border-top: 1px solid var(--mp-border); margin: 8px 0; }
/* Help link — deliberately the loudest thing in the side rail. If the
 * operator is ever unsure what to click, this is the escape hatch, so it
 * must not blend into the navigation above it. */
.rnav .is-help-link {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 11px 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffd76a 0%, #ffb020 100%);
  border: 2px solid #b8791a;
  color: #40270a;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(184, 121, 26, 0.35);
}
.rnav .is-help-link:hover {
  background: linear-gradient(135deg, #ffe28c 0%, #ffc247 100%);
  color: #40270a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(184, 121, 26, 0.45);
}
.rnav .is-help-link__badge {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  line-height: 26px;
  text-align: center;
  border-radius: 50%;
  background: #40270a;
  color: #ffd76a;
  font-size: 16px;
  font-weight: 800;
}
.rnav .is-help-link__label {
  display: block;
  line-height: 1.25;
}
.rnav .is-help-link__label small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #6b4413;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---- Main ---- */
.main {
  margin-left: 0;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

/* ---- Buttons ---- */
.is-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  border: 1px solid var(--mp-border); background: var(--mp-surface);
  color: var(--mp-text); text-decoration: none; cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.is-btn:hover { background: #f5f5fa; }
.is-btn-primary {
  background: var(--mp-purple); color: #fff; border-color: var(--mp-purple);
}
.is-btn-primary:hover { background: var(--mp-purple-dark); border-color: var(--mp-purple-dark); }
.is-btn-ghost { background: transparent; border-color: var(--mp-border); }
.is-btn-danger { background: var(--mp-error); color: #fff; border-color: var(--mp-error); }
.is-btn-danger:hover { background: #8b1818; border-color: #8b1818; }
.is-btn-sm { padding: 4px 8px; font-size: 12px; border-radius: 6px; }

.inline-form { display: inline-block; margin: 0 2px; }

/* ---- Page heads / empty state ---- */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.page-head h1 { font-size: 22px; margin: 0; color: var(--mp-purple-dark); }
.page-head__actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty {
  padding: 40px 16px; text-align: center; color: var(--mp-muted);
  background: var(--mp-surface); border: 1px dashed var(--mp-border); border-radius: var(--radius);
}
.empty .is-btn { margin-top: 10px; }

.muted { color: var(--mp-muted); }
.small { font-size: 12px; }

/* ---- "What to click" instructions ---------------------------------
 * Shown on the pages the operator actually works from. Deliberately
 * verbose and concrete: it names the buttons in the order they are
 * pressed, and explains what each step changes. Tone assumes no
 * technical knowledge. */
.howto {
  background: #f4f1ff;
  border: 1px solid #d5c9ff;
  border-left: 6px solid var(--mp-purple);
  border-radius: 8px;
  padding: 16px 20px;
  margin: 16px 0 22px;
}
.howto__head {
  font-size: 16px;
  font-weight: 700;
  color: var(--mp-purple-dark);
  margin-bottom: 10px;
}
.howto__steps {
  margin: 0;
  padding-left: 22px;
  font-size: 14.5px;
  line-height: 1.65;
  color: #2c2440;
}
.howto__steps li { margin-bottom: 7px; }
.howto__steps li:last-child { margin-bottom: 0; }
.howto__steps strong { color: var(--mp-purple-dark); }
.howto__note {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #fff;
  border-radius: 6px;
  font-size: 13.5px;
  line-height: 1.55;
  color: #4a4260;
}
.howto__legend {
  margin: 0 0 4px;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.6;
  color: #2c2440;
}
.howto__legend li { margin-bottom: 6px; }
.howto__legend .status { margin-right: 6px; }
.howto__routes {
  margin: 10px 0 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.6;
  color: #2c2440;
}
.howto__routes li { margin-bottom: 8px; }

/* ---- Issue form: the two choices side by side ----
 * Step 1 (student) and Step 2 (which certificate) sit in two columns so
 * it reads as "pick these two things" rather than a long form. */
.issue-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.issue-grid__col {
  min-width: 0;
}
.issue-grid__chosen { margin-bottom: 12px; }
.step-badge {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  background: var(--mp-purple);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: 2px;
}
.template-grid--compact {
  grid-template-columns: 1fr;
  max-height: 340px;
  overflow-y: auto;
  padding: 2px;
}

@media (max-width: 860px) {
  .issue-grid { grid-template-columns: 1fr; }
}

/* ---- Form field labels + per-field help --------------------------
 * .field-name is the visible label; .field-help is the explanation of
 * what the value is for and how it prints. */
.cert-form label .field-name {
  display: block;
  font-weight: 600;
  font-size: 15px;
  color: var(--mp-text);
  margin-bottom: 4px;
}
.cert-form label .field-name .req {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #b22222;
  background: #fdecec;
  border-radius: 3px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}
.cert-form label .field-name .opt {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5a5a70;
  background: #eeeef4;
  border-radius: 3px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}
.cert-form label .field-help {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.55;
  color: #55556a;
  max-width: 70ch;
}
.cert-form label .field-help strong { color: #33334a; }

/* A field the app filled in for the operator (e.g. the student chosen
   when arriving from their page). Tinted so it's obvious it's already
   set but still freely editable. */
.is-prefilled {
  background: #f5f1ff;
  border-color: #b9a8ff;
}

/* ---- Tabs (filter strip) ---- */
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap; align-items: center;
  margin-bottom: 12px;
}
.tab {
  padding: 6px 12px; border-radius: 999px;
  background: var(--mp-surface); border: 1px solid var(--mp-border);
  color: var(--mp-text); text-decoration: none; font-size: 13px;
}
.tab:hover { background: #f0eaff; }
.tab.is-active {
  background: var(--mp-purple); color: #fff; border-color: var(--mp-purple);
}
.tab .pill {
  display: inline-block; min-width: 22px; padding: 0 6px;
  margin-left: 4px; border-radius: 999px;
  background: rgba(0,0,0,0.08); font-size: 11px; line-height: 18px;
  text-align: center;
}
.tab.is-active .pill { background: rgba(255,255,255,0.25); }

.search { margin-left: auto; }
.search input[type=search] {
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--mp-border);
  background: var(--mp-surface); font-size: 13px; min-width: 180px;
}

/* ---- Flash messages ---- */
.flash {
  padding: 10px 14px; border-radius: var(--radius); margin: 10px 0;
  font-size: 14px;
}
.flash-ok    { background: #e3f5ec; color: var(--mp-success); border-left: 4px solid var(--mp-success); }
.flash-error { background: #fce4e4; color: var(--mp-error); border-left: 4px solid var(--mp-error); }
.flash-info  { background: #e1ecf8; color: var(--mp-info); border-left: 4px solid var(--mp-info); }

/* ---- Table ---- */
.cert-table {
  width: 100%; border-collapse: collapse; background: var(--mp-surface);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); font-size: 14px;
}
.cert-table th, .cert-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--mp-border);
}
.cert-table th { background: #f0eaff; color: var(--mp-purple-dark); font-weight: 600; }
.cert-table tr:last-child td { border-bottom: none; }
.cert-table .num { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-weight: 600; }
.cert-table .actions { white-space: nowrap; }
.cert-table .actions-col { width: 1%; white-space: nowrap; }
.status {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.status-available { background: #fff4d6; color: var(--mp-warn); }
.status-issued    { background: #e3f5ec; color: var(--mp-success); }
.status-archived  { background: #ececf2; color: var(--mp-muted); }

/* ---- Forms ---- */
.cert-form { max-width: 760px; }
.cert-form fieldset {
  border: 1px solid var(--mp-border); border-radius: var(--radius);
  padding: 12px 16px; margin: 0 0 14px; background: var(--mp-surface);
}
.cert-form legend { padding: 0 8px; color: var(--mp-purple-dark); font-weight: 600; }
.cert-form label {
  display: block; margin: 10px 0; font-size: 13px; color: var(--mp-muted);
}
.cert-form input[type=text],
.cert-form input[type=date],
.cert-form select,
.cert-form textarea {
  display: block; width: 100%;
  margin-top: 4px;
  padding: 8px 10px; border: 1px solid var(--mp-border); border-radius: 6px;
  background: var(--mp-surface); color: var(--mp-text);
  font: inherit; font-size: 14px;
}
.cert-form textarea { resize: vertical; min-height: 80px; }
.cert-form .form-actions {
  display: flex; gap: 8px; margin-top: 16px;
}

/* ---- Login + help pages ---- */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: linear-gradient(135deg, var(--mp-purple) 0%, var(--mp-purple-dark) 100%);
}
.login-card {
  background: var(--mp-surface); border-radius: var(--radius);
  padding: 28px 24px; max-width: 420px; width: 100%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.login-card h1 { margin: 0 0 4px; color: var(--mp-purple-dark); }
.login-card label { display: block; margin: 10px 0; font-size: 13px; color: var(--mp-muted); }
.login-card input {
  display: block; width: 100%; margin-top: 4px;
  padding: 9px 11px; border: 1px solid var(--mp-border); border-radius: 6px;
  font: inherit; font-size: 14px;
}
.login-card button { width: 100%; margin-top: 14px; padding: 10px; font-size: 15px; justify-content: center; }
.login-card .footer-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--mp-muted); }

.help-card { max-width: 640px; text-align: left; }
.help-card h1 { text-align: center; }
.help-card h2 {
  font-size: 16px; margin-top: 22px; margin-bottom: 6px;
  color: var(--mp-purple-dark);
  border-bottom: 1px solid var(--mp-border); padding-bottom: 4px;
}
.help-card p, .help-card li { font-size: 14px; }
.help-toc {
  background: #f0eaff; padding: 10px 14px; border-radius: 8px;
  display: flex; flex-direction: column; gap: 4px; margin: 16px 0;
}
.help-toc a { font-size: 13px; }

/* ---- Notes block on view page ---- */
.notes-block {
  margin-top: 24px; padding: 12px 16px;
  background: #fff8e1; border-left: 4px solid var(--mp-gold);
  border-radius: 6px;
}
.notes-block h3 { margin: 0 0 6px; font-size: 14px; color: var(--mp-gold-dark); }

/* ---- Certificate card ----
 * The certificate layout lives entirely in assets/cert-print.css so the
 * on-screen view, the browser print-out and the server-side PDF all
 * render the same thing. Do not duplicate cert styles here.
 *
 * The frame is a fixed 1100x777px box (explicit px, because dompdf
 * ignores aspect-ratio/cqw). On a narrow screen that overflows, so we
 * scale it with a transform. `.cert-scale` is sized by the tiny script
 * at the bottom of certificate_view.php; the height reservation keeps
 * the scale from leaving a gap.
 */
.cert-card {
  padding: 0;
}
.cert-scale {
  /* The certificate is authored at exactly 1122x794 (= A4 landscape at
     96dpi). certificate_view.php sets element.style.zoom from the window
     size so the whole cert fits without scrolling. `zoom` rather than
     `transform: scale()` because zoom shrinks the layout box too, so no
     scrollbar appears. Print and PDF ignore this entirely: @media print
     pins the page to A4 and the frame is already the correct size.
     zoom: 1 is the fallback if JS is unavailable. */
  zoom: 1;
  width: 1122px;
  margin: 0 auto;
}

/* ---- Big instructions banner (above forms/list pages) ---- */
.big-instructions {
  background: #fff8e1;
  border-left: 6px solid var(--mp-gold);
  padding: 14px 18px;
  border-radius: 8px;
  margin: 16px 0;
  font-size: 15px;
  line-height: 1.55;
  color: #3a2e10;
}
.big-instructions strong { color: var(--mp-gold-dark); }

/* ---- Template picker (radio cards) ---- */
.template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}
@media (min-width: 720px) {
  .template-grid { grid-template-columns: 1fr 1fr; }
}
.template-card {
  display: block;
  padding: 16px 18px;
  border: 2px solid var(--mp-border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--mp-surface);
  transition: border-color 0.12s, background 0.12s;
}
.template-card:hover { border-color: var(--mp-purple); background: #faf8ff; }
.template-card.is-selected { border-color: var(--mp-purple); background: #f0eaff; }
.template-card input[type=radio] { position: absolute; opacity: 0; pointer-events: none; }
.template-card__title {
  font-size: 18px; font-weight: 700; color: var(--mp-purple-dark);
}
.template-card__cat {
  font-size: 12px; color: var(--mp-muted);
  letter-spacing: 1px; text-transform: uppercase; margin-top: 2px;
}
.template-card__sig { font-size: 13px; color: #555; margin-top: 8px; }

/* ---- Read-only field grid (for cert edit "locked wording" section) ---- */
dl.readonly-fields {
  display: grid; grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  margin: 8px 0 0;
}
dl.readonly-fields dt {
  color: var(--mp-muted); font-size: 13px; font-weight: 600;
  text-align: right; padding-top: 2px;
}
dl.readonly-fields dd {
  margin: 0; font-size: 14px; color: var(--mp-text);
}
dl.readonly-fields .readonly-body {
  background: #f8f8fc; padding: 8px 12px; border-radius: 6px;
  border: 1px solid var(--mp-border);
  font-size: 13px; line-height: 1.5;
}

/* ---- Assign-number callout ---- */
.assign-form {
  background: linear-gradient(135deg, #f0eaff 0%, #e1f5ea 100%);
  border: 2px solid var(--mp-purple);
  border-radius: 10px;
  padding: 18px 20px;
  margin: 16px 0;
  text-align: center;
}
.assign-form p { margin: 8px 0 0; font-size: 13px; }

/* ---- Large primary action button ---- */
.is-btn-large {
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 700;
}

/* ---- Responsive (>=720px) ---- */
@media (min-width: 720px) {
  .topbar .hamburger { display: none; }
  body.nav-open .scrim { display: none; }
  .rnav {
    transform: translateX(0);
    padding-top: 70px;
  }
  .main { margin-left: 240px; padding: 24px 32px; }
  .help-card, .login-card { padding: 36px 32px; }
}

/* ---- Print ---- */
@media print {
  .topbar, .rnav, .scrim, .page-head, .flash, .notes-block,
  .cert-status-line, .tabs, .search, .footer, form { display: none !important; }
  body, .login-page { background: #fff !important; }
  .main { margin: 0 !important; padding: 0 !important; max-width: none !important; }
  .cert-card { padding: 0 !important; }
  .cert-border { box-shadow: none !important; }
}