:root,
body.theme-dark,
body[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2f3f56;
  --text: #e8eef6;
  --muted: #9aadc2;
  --accent: #3b9eff;
  --accent-dim: #2563a8;
  --ok: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --student: #60a5fa;
  --facilitator: #c084fc;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --topbar-bg: linear-gradient(180deg, rgba(18, 26, 38, 0.97) 0%, rgba(12, 17, 26, 0.94) 100%);
  --topbar-border: rgba(47, 63, 86, 0.9);
  --body-bg:
    radial-gradient(1200px 600px at 10% -10%, #1b3a5c 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #2a1f4d 0%, transparent 50%),
    var(--bg);
  --input-bg: var(--bg);
  --flash-ok-bg: rgba(52, 211, 153, 0.12);
  --flash-error-bg: rgba(248, 113, 113, 0.12);
}

/* Light mode skin (facilitator preference) */
body.theme-light,
body[data-theme="light"] {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface2: #eef2f7;
  --border: #d0dae6;
  --text: #0f172a;
  --muted: #5b6b7c;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --ok: #059669;
  --warn: #d97706;
  --error: #dc2626;
  --student: #2563eb;
  --facilitator: #7c3aed;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
  --topbar-bg: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  --topbar-border: #e2e8f0;
  --body-bg:
    radial-gradient(1100px 520px at 8% -8%, #dbeafe 0%, transparent 55%),
    radial-gradient(900px 480px at 100% 0%, #ede9fe 0%, transparent 50%),
    var(--bg);
  --input-bg: #ffffff;
  --flash-ok-bg: rgba(5, 150, 105, 0.1);
  --flash-error-bg: rgba(220, 38, 38, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--body-bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.narrow { max-width: 480px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  min-height: 72px;
  padding: 0.65rem 1.75rem;
  border-bottom: 1px solid var(--topbar-border);
  background: var(--topbar-bg);
  backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset,
              0 8px 24px rgba(0, 0, 0, 0.12);
  position: sticky;
  top: 0;
  z-index: 40;
}
body.theme-light .topbar {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset,
              0 4px 16px rgba(15, 23, 42, 0.06);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none !important;
  flex-shrink: 0;
}
.brand:hover { color: #fff; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(43, 127, 212, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.brand:hover .brand-mark {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(59, 158, 255, 0.45);
}
.brand-logo {
  width: 40px;
  height: 40px;
  display: block;
  border-radius: 12px;
}
.brand-text {
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
/* FormIDable — ID in red, able in blue */
.brand-id,
.footer .brand-id {
  color: #ef4444;
  font-weight: 800;
}
.brand-able,
.footer .brand-able {
  color: #3b9eff;
  font-weight: 700;
}

/* Unified top-nav control height */
:root {
  --nav-control-h: 40px;
}
.nav {
  display: flex;
  gap: 0.35rem 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.nav > form {
  display: inline-flex;
  align-items: center;
  margin: 0;
  height: var(--nav-control-h);
}
.nav > a:not(.nav-user),
.nav .btn,
.nav .token-chip-nav,
.nav .nav-bell {
  box-sizing: border-box;
  height: var(--nav-control-h);
  min-height: var(--nav-control-h);
  max-height: var(--nav-control-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.85rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  margin: 0;
}
.nav > a:not(.nav-user) {
  color: var(--muted);
  text-decoration: none !important;
  transition: background 0.12s, color 0.12s;
}
.nav > a:not(.nav-user):hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
.nav-sep {
  width: 1px;
  height: calc(var(--nav-control-h) - 12px);
  background: var(--border);
  margin: 0 0.35rem;
  flex-shrink: 0;
  align-self: center;
}
.nav .who,
.nav-user {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none !important;
  height: var(--nav-control-h);
  min-height: var(--nav-control-h);
  max-height: var(--nav-control-h);
  padding: 0 0.65rem 0 0.2rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  max-width: 240px;
  box-sizing: border-box;
}
a.nav-user:hover {
  background: rgba(59, 158, 255, 0.1);
  border-color: rgba(59, 158, 255, 0.35);
  color: #fff;
}
/* Keep avatar within unified nav control height */
.nav-user .nav-avatar,
.nav-user .nav-avatar-fallback {
  width: 32px !important;
  height: 32px !important;
  min-width: 32px !important;
  min-height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
  font-size: 0.85rem;
}
.nav-user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.15;
}
.nav-user-meta {
  display: block;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.nav .btn.ghost {
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
}

/* Student skin switcher (portal top bar) */
.nav-theme-switch {
  display: inline-flex;
  align-items: stretch;
  height: var(--nav-control-h);
  margin: 0;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  gap: 2px;
  box-sizing: border-box;
}
body.theme-light .nav-theme-switch {
  background: rgba(15, 23, 42, 0.04);
}
.nav-theme-opt {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
  height: calc(var(--nav-control-h) - 6px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-theme-opt:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
body.theme-light .nav-theme-opt:hover {
  background: rgba(15, 23, 42, 0.06);
}
.nav-theme-opt.is-active {
  background: var(--accent);
  color: #041018;
}
body.theme-light .nav-theme-opt.is-active,
body[data-theme="light"] .nav-theme-opt.is-active {
  color: #ffffff;
}

/* Notification bell */
.nav-notif {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: var(--nav-control-h);
}
.nav-bell {
  position: relative;
  width: var(--nav-control-h);
  min-width: var(--nav-control-h);
  padding: 0 !important;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
}
.nav-bell:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(59, 158, 255, 0.4);
}
.nav-bell-icon {
  display: block;
}
.nav-bell-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.05rem;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}
.nav-notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(340px, 92vw);
  max-height: min(420px, 70vh);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  padding: 0.5rem;
}
.nav-notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}
.nav-notif-markall {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  padding: 0.25rem 0.45rem !important;
  font-size: 0.75rem !important;
}
.nav-notif-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-notif-item {
  border-radius: 8px;
  margin-bottom: 0.2rem;
}
.nav-notif-item.is-unread {
  background: rgba(59, 158, 255, 0.1);
}
.nav-notif-go { margin: 0; }
.nav-notif-link {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.55rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
button.nav-notif-link:hover {
  background: rgba(255, 255, 255, 0.06);
}
.nav-notif-title {
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.25;
}
.nav-notif-body {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}
.nav-notif-time {
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.85;
}
.nav-notif-empty {
  padding: 0.75rem 0.5rem;
  margin: 0;
}

.hero {
  padding: 4rem 1.25rem 3rem;
  text-align: center;
}
.hero-logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.1rem;
}
.hero-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(15, 40, 80, 0.35);
}
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 0.75rem; letter-spacing: -0.03em; }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 1.5rem; font-size: 1.05rem; }
.hero-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card h2, .card h3 { margin-top: 0; }
.card.muted-card { background: var(--surface2); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
textarea, select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  margin-bottom: 0.85rem;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}
textarea { min-height: 100px; resize: vertical; }
input:disabled, textarea:disabled, select:disabled {
  opacity: 0.55; cursor: not-allowed;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: none; border-radius: 8px;
  padding: 0.6rem 1rem;
  font: inherit; font-weight: 600;
  cursor: pointer;
  background: var(--accent); color: #041018;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: #b91c1c; color: white; }
.btn.ok { background: var(--ok); color: #052e1a; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.5rem; }

/* Light mode: primary accent is dark blue — use white label text */
body.theme-light .btn:not(.secondary):not(.ghost):not(.danger):not(.ok),
body[data-theme="light"] .btn:not(.secondary):not(.ghost):not(.danger):not(.ok) {
  color: #ffffff;
}
body.theme-light .btn.ok,
body[data-theme="light"] .btn.ok {
  color: #ffffff;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid;
}
.flash.ok { background: var(--flash-ok-bg); border-color: #059669; color: var(--ok); }
.flash.error { background: var(--flash-error-bg); border-color: #dc2626; color: var(--error); }
body.theme-light .flash.ok { color: #047857; }
body.theme-light .flash.error { color: #b91c1c; }

/* Profile skin picker */
.skin-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin: 0.5rem 0 0.25rem;
}
@media (max-width: 520px) {
  .skin-options { grid-template-columns: 1fr; }
}
.skin-option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.skin-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}
.skin-option.is-selected,
.skin-option:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 158, 255, 0.25);
}
.skin-option-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  line-height: 1.25;
}
.skin-option-text .meta { margin: 0; }
.skin-swatch {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.skin-swatch-dark {
  background:
    linear-gradient(135deg, #1b3a5c 0%, #0f1419 55%, #2a1f4d 100%);
}
.skin-swatch-light {
  background:
    linear-gradient(135deg, #dbeafe 0%, #ffffff 50%, #ede9fe 100%);
  border-color: #cbd5e1;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.student { color: var(--student); border-color: #1d4ed8; background: rgba(59, 130, 246, 0.12); }
.badge.facilitator { color: var(--facilitator); border-color: #7e22ce; background: rgba(192, 132, 252, 0.12); }
.badge.facilitator_global {
  color: #d97706;
  border-color: #b45309;
  background: rgba(245, 158, 11, 0.14);
}
.badge.signature { color: var(--warn); border-color: #b45309; background: rgba(251, 191, 36, 0.1); }
.badge.status-draft { color: var(--muted); }
.badge.status-in_progress { color: var(--accent); border-color: var(--accent-dim); }
.badge.status-ready { color: var(--warn); border-color: #b45309; }
.badge.status-submitted { color: var(--ok); border-color: #059669; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left; padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }

.progress {
  height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden;
  border: 1px solid var(--border);
}
.progress > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
}

.field-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.9rem;
  background: var(--surface2);
}
.field-block.readonly { opacity: 0.85; }
.field-head {
  display: flex; justify-content: space-between; gap: 0.75rem;
  align-items: flex-start; margin-bottom: 0.5rem; flex-wrap: wrap;
}
.field-label { font-weight: 600; margin: 0; color: var(--text); }
.section-title {
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sig-pad-wrap {
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  max-width: 480px;
}
.sig-pad-wrap canvas { display: block; width: 100%; height: 140px; touch-action: none; cursor: crosshair; }
.sig-preview {
  max-width: 320px; background: #fff; border-radius: 8px; padding: 0.4rem;
  border: 1px solid var(--border);
}
.sig-preview img { max-width: 100%; display: block; }

.doc-preview {
  background: #f8fafc; color: #0f172a;
  border-radius: 8px; padding: 1rem 1.25rem;
  max-height: 360px; overflow: auto;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.doc-preview img { max-width: 100%; }

/* ── Document-as-form surface ─────────────────────────────── */
.doc-form-shell {
  background: #e8edf3;
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}
.doc-paper {
  background: #fff;
  color: #0f172a;
  border-radius: 4px;
  padding: 1.75rem 1.9rem;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.12);
  font-family: "Calibri", "Segoe UI", Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.35;
  overflow-x: auto;
  max-width: 100%;
}
.doc-paper table, .doc-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.4rem 0 0.75rem;
  font-size: 10.5pt;
}
.doc-paper td, .doc-paper th, .doc-td {
  border: 1px solid #94a3b8;
  padding: 0.4rem 0.5rem;
  vertical-align: middle;
}
.doc-td-header {
  background: #0b4655 !important;
  color: #fff !important;
  font-weight: 700;
}
.doc-td-blue {
  background: #deeaf6 !important;
  min-width: 4rem;
  min-height: 1.6rem;
}
.doc-td-blue .cri-input,
.doc-td-blue .cri-textarea {
  background: #f8fbff !important;
  border-color: #5b9bd5 !important;
}
.doc-heading {
  font-weight: 700;
  color: #0b4655;
  font-size: 1.05rem;
  margin: 0.9rem 0 0.4rem;
}
.doc-p { margin: 0.35rem 0; }
.doc-spacer { height: 0.4rem; }
.doc-inline-img { max-height: 72px; max-width: 200px; vertical-align: middle; }
.doc-paper li { margin: 0.2rem 0; }
.doc-paper strong { color: #0f172a; }

/* Yes / No clickable checkboxes */
.cri-yn {
  display: inline-flex !important;
  align-items: center;
  gap: 0.25rem;
  margin: 0 0.55rem 0 0 !important;
  color: #0f172a !important;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.cri-yn .cri-check { margin: 0; }
.cri-yn-text { min-width: 1.6rem; }
.cri-yn-bare { min-width: auto; gap: 0; }
.doc-td-check { white-space: nowrap; }

.cri-ph {
  display: inline-block;
  min-width: 1.2rem;
  min-height: 1.1rem;
  background: #dbeafe;
  border: 1px dashed #3b82f6;
  border-radius: 3px;
  vertical-align: middle;
}
.cri-widget { display: inline-flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; max-width: 100%; }
.cri-input {
  background: #f8fafc !important;
  border: 1px solid #64748b !important;
  color: #0f172a !important;
  border-radius: 4px !important;
  padding: 0.25rem 0.4rem !important;
  margin: 0.1rem 0 !important;
  font: inherit !important;
  min-width: 6rem;
  max-width: none; /* allow horizontal growth past cell default */
  box-sizing: border-box;
}
/* Horizontally resizable text field wrapper (inputs ignore CSS resize) */
.cri-resize-x {
  display: inline-block;
  width: 100%;
  min-width: 8rem;
  max-width: min(100vw, 900px);
  resize: horizontal;
  overflow: hidden;
  vertical-align: middle;
  box-sizing: border-box;
}
.cri-resize-x .cri-input.cri-text,
.cri-resize-x input.cri-text {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  resize: none !important;
  display: block;
}
/* Textareas: extend horizontally (and vertically); size can be persisted via inline style */
.cri-input.cri-textarea,
textarea.cri-textarea {
  display: block;
  width: 100%;
  min-width: 10rem;
  max-width: min(100vw, 900px);
  min-height: 4rem;
  resize: both;
  overflow: auto;
  box-sizing: border-box;
}
.cri-date { min-width: 9rem; width: auto; }
.doc-td-blue .cri-resize-x {
  width: 100%;
  min-width: 100%;
}
.doc-td-blue .cri-textarea {
  width: 100%;
  min-width: 100%;
}

.cri-choice { display: inline-flex; flex-wrap: wrap; gap: 0.35rem 0.75rem; align-items: center; }
.cri-choice.compact { gap: 0.25rem 0.5rem; }
.cri-check {
  display: inline-flex !important;
  align-items: center;
  gap: 0.3rem;
  color: #0f172a !important;
  font-size: 0.95em;
  margin: 0 !important;
  cursor: pointer;
  user-select: none;
}
.cri-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.cri-box, .cri-radio {
  width: 1.05rem; height: 1.05rem;
  border: 2px solid #334155;
  background: #fff;
  display: inline-block;
  flex-shrink: 0;
  position: relative;
}
.cri-radio { border-radius: 50%; }
.cri-box { border-radius: 3px; }
.cri-check input:checked + .cri-box {
  background: #2563eb;
  border-color: #1d4ed8;
}
.cri-check input:checked + .cri-box::after {
  content: "";
  position: absolute;
  left: 0.28rem; top: 0.05rem;
  width: 0.28rem; height: 0.55rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.cri-check input:checked + .cri-radio {
  border-color: #2563eb;
  box-shadow: inset 0 0 0 3px #2563eb;
}
.cri-check input:disabled + .cri-box,
.cri-check input:disabled + .cri-radio { opacity: 0.55; cursor: not-allowed; }

.cri-mini-badge {
  width: 0.45rem; height: 0.45rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.cri-mini-badge.student { background: #3b82f6; }
.cri-mini-badge.facilitator { background: #a855f7; }
.cri-mini-badge.facilitator_global { background: #f59e0b; }

.cri-owner-facilitator .cri-input { border-color: #a855f7 !important; background: #faf5ff !important; }
.cri-owner-facilitator_global .cri-input { border-color: #f59e0b !important; background: #fffbeb !important; }
.cri-owner-student .cri-input { border-color: #3b82f6 !important; background: #eff6ff !important; }

.cri-sig { display: flex; flex-direction: column; gap: 0.35rem; max-width: 28rem; }
.cri-sig .sig-pad-wrap { max-width: 100%; }
.cri-sig .sig-preview.typed {
  font-family: "Segoe Script", "Comic Sans MS", cursive;
  font-size: 1.35rem;
  color: #0f172a;
  padding: 0.35rem 0.5rem;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}
.cri-empty-sig { color: #64748b; font-style: italic; font-size: 0.9em; }

.template-preview .cri-ph { min-width: 4rem; min-height: 1.3rem; }
.template-preview .cri-ph-checkbox { min-width: 1.2rem; }
.template-preview .cri-ph-choice { min-width: 8rem; min-height: 1.5rem; }
.template-preview .cri-ph-signature { min-width: 10rem; min-height: 2.5rem; }
.template-preview .cri-ph-textarea { min-width: 100%; min-height: 3rem; display: block; }

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(8px);
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: 10;
}
.form-actions { margin: 0.5rem 0 1.5rem; }

.container.wide-form, .doc-form-shell { max-width: 100%; }
/* Wider canvas for form fill + document design (checkboxes/choices need room) */
@media (min-width: 900px) {
  main.container:has(.doc-form-shell) { max-width: 1400px; }
  main.container:has(.config-canvas-card) { max-width: 1400px; }
}
@media (min-width: 1500px) {
  main.container:has(.doc-form-shell) { max-width: 1600px; }
  main.container:has(.config-canvas-card) { max-width: 1600px; }
}

/* Rich Word-like paper — allow wider than A4 when fields need space */
.doc-paper {
  background: #fff;
  color: #0f172a;
}
.doc-paper.doc-paper-form,
.doc-form-shell .doc-paper,
.config-canvas-card .doc-paper {
  max-width: min(100%, 320mm) !important;
  width: 100%;
}
.doc-form-shell .doc-table,
.config-canvas-card .doc-table {
  table-layout: auto;
}
.doc-form-shell .doc-td-check,
.config-canvas-card .doc-td-check {
  white-space: nowrap;
  min-width: 2.2rem;
  text-align: center;
}
.cri-choice-radio {
  display: inline-flex;
  margin: 0 0.15rem;
}
.cri-config-choice {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 2.5rem;
  padding: 0.2rem 0.4rem;
}
.cri-config-choice .cri-radio {
  width: 1rem;
  height: 1rem;
  border: 2px solid #64748b;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.doc-img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  display: inline-block;
}
.doc-table {
  table-layout: fixed;
}
.doc-table col { min-width: 0; }
.doc-td p { margin: 0.15rem 0; }
.doc-td .doc-p { margin: 0.1rem 0; }

/* Template config: full-width canvas */
.config-canvas-card { min-width: 0; }

/* Field properties modal */
body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 12, 20, 0.62);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none !important; }
.modal-dialog {
  width: min(440px, 100%);
  max-height: min(90vh, 640px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem 1.25rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}
.modal-close {
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.2rem 0.55rem !important;
  min-width: auto;
}

.cri-configurable {
  cursor: pointer;
  display: inline-block;
  max-width: 100%;
  vertical-align: middle;
  border-radius: 4px;
  outline: 2px solid transparent;
  transition: outline-color 0.12s, box-shadow 0.12s;
}
.cri-configurable:hover {
  outline-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 158, 255, 0.25);
}
.cri-configurable.is-active {
  outline-color: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35);
}
.cri-config-shell {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  min-height: 1.4rem;
  min-width: 3.5rem;
  padding: 0.2rem 0.35rem;
  border: 1px dashed #64748b;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.65);
  font-size: 0.78rem;
  color: #0f172a;
}
.cri-config-area {
  display: flex;
  width: 100%;
  min-height: 2.6rem;
  align-items: flex-start;
}
.cri-config-sig {
  min-width: 8rem;
  min-height: 2rem;
  font-style: italic;
}
.cri-config-check {
  min-width: 1.4rem;
  padding: 0.15rem;
}
.cri-config-tag {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #475569;
  background: #e2e8f0;
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
  white-space: nowrap;
}
.cri-owner-student.cri-config-shell,
.cri-config-shell.cri-owner-student {
  border-color: #3b82f6;
  background: #eff6ff;
}
.cri-owner-facilitator.cri-config-shell,
.cri-config-shell.cri-owner-facilitator {
  border-color: #a855f7;
  background: #faf5ff;
}
.cri-owner-facilitator_global.cri-config-shell,
.cri-config-shell.cri-owner-facilitator_global {
  border-color: #f59e0b;
  background: #fffbeb;
}

.field-ctx-menu {
  position: absolute;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 200px;
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.field-ctx-menu[hidden] { display: none !important; }
.field-ctx-menu button {
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
.field-ctx-menu button:hover {
  background: var(--surface2);
}
.field-ctx-menu button.ctx-danger {
  color: var(--error);
}
.field-ctx-menu button.ctx-danger:hover {
  background: rgba(248, 113, 113, 0.12);
}
.cri-configurable.is-removed .cri-config-shell,
.cri-config-shell.cri-config-none {
  opacity: 0.55;
  border-style: dotted;
  background: #f1f5f9 !important;
  border-color: #94a3b8 !important;
  text-decoration: line-through;
}
.cri-field-none {
  display: inline;
}

/* Admin token top-up row form */
.admin-token-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin: 0;
}
.admin-token-form input[type="number"] {
  width: 5.5rem;
  margin: 0;
  padding: 0.35rem 0.45rem;
}
.admin-token-form input[type="text"] {
  width: 9rem;
  margin: 0;
  padding: 0.35rem 0.45rem;
  flex: 1;
  min-width: 6rem;
}
.admin-token-form .btn {
  margin: 0;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

/* Document import — colour mapping (visual swatches) */
.color-map-fields {
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  transition: opacity 0.15s ease;
}
.color-map-fields.is-ghosted {
  opacity: 0.45;
  pointer-events: none;
  filter: grayscale(0.25);
}
.color-picker-block {
  min-width: 0;
}
.color-picker-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
}
.color-swatch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.color-swatch {
  position: relative;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 8px;
  border: 2px solid rgba(0, 0, 0, 0.22);
  padding: 0;
  margin: 0;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
  background: #ccc;
}
.color-swatch:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.color-swatch:focus-visible {
  outline: 2px solid var(--accent, #3b9eff);
  outline-offset: 2px;
}
.color-swatch.is-selected {
  box-shadow:
    0 0 0 2px var(--surface, #0f1419),
    0 0 0 4px var(--accent, #3b9eff),
    0 2px 8px rgba(0, 0, 0, 0.18);
  transform: scale(1.06);
}
.color-swatch:disabled {
  cursor: not-allowed;
}
.color-swatch-none {
  background:
    linear-gradient(135deg, transparent 46%, #94a3b8 46%, #94a3b8 54%, transparent 54%),
    #f1f5f9 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.color-swatch-none-x {
  font-size: 1.1rem;
  line-height: 1;
  color: #64748b;
  font-weight: 700;
}
.color-swatch-count {
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 1rem;
  height: 1rem;
  padding: 0 3px;
  border-radius: 999px;
  background: rgba(15, 20, 25, 0.85);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1rem;
  text-align: center;
  pointer-events: none;
}
.color-chip-row {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.color-chip {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

/* Profile — fixed 150×150 display */
.profile-photo-block {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.profile-photo {
  width: 150px !important;
  height: 150px !important;
  min-width: 150px;
  min-height: 150px;
  max-width: 150px;
  max-height: 150px;
  border-radius: 12px;
  object-fit: cover;
  object-position: center;
  border: 2px solid var(--border);
  background: var(--surface2);
  display: block;
  flex-shrink: 0;
}
.profile-photo-actions {
  flex-wrap: wrap;
  gap: 0.5rem;
}
.profile-photo-actions .btn {
  margin: 0;
}
.nav-avatar {
  width: 50px !important;
  height: 50px !important;
  min-width: 50px;
  min-height: 50px;
  max-width: 50px;
  max-height: 50px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  flex-shrink: 0;
  border: 2px solid rgba(59, 158, 255, 0.45);
  box-shadow: 0 0 0 2px rgba(15, 20, 25, 0.9);
  background: var(--surface2);
  display: block;
}
.nav-avatar-fallback {
  width: 50px;
  height: 50px;
  min-width: 50px;
  min-height: 50px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  background: linear-gradient(145deg, #3b9eff, #2563a8);
  border: 2px solid rgba(59, 158, 255, 0.45);
  flex-shrink: 0;
}
.nav-avatar-default {
  object-fit: cover;
  background: #1a4f8a;
}
.profile-photo-default {
  object-fit: cover;
  background: #1a4f8a;
}
.profile-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}
.doc-td-field {
  background-color: #f0f7fc;
}

/* Marketing / pricing */
.currency-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.currency-pill {
  display: inline-block;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none !important;
}
.currency-pill:hover { border-color: var(--accent); }
.currency-pill.is-active {
  background: rgba(59, 158, 255, 0.18);
  border-color: var(--accent);
  color: #fff;
}
.price-hero {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0.35rem 0 0.5rem;
}
.price-hero .meta { font-size: 1rem; font-weight: 500; }
.pricing-table td:nth-child(2),
.pricing-table th:nth-child(2),
.pricing-table td:nth-child(3),
.pricing-table th:nth-child(3) {
  text-align: right;
  white-space: nowrap;
}
.token-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(59, 158, 255, 0.1);
  min-width: 5.5rem;
}
.token-chip-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}
.token-chip strong {
  font-size: 1.35rem;
  color: var(--accent);
  line-height: 1.2;
}
/* Always-visible balance in the title bar (matches --nav-control-h) */
.token-chip-nav {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 4.25rem;
  height: var(--nav-control-h);
  min-height: var(--nav-control-h);
  max-height: var(--nav-control-h);
  padding: 0 0.7rem;
  margin-right: 0.15rem;
  border-radius: 8px;
  border: 1px solid rgba(59, 158, 255, 0.45);
  background: rgba(59, 158, 255, 0.12);
  text-decoration: none !important;
  color: var(--text);
  line-height: 1.05;
  box-sizing: border-box;
}
.token-chip-nav:hover {
  background: rgba(59, 158, 255, 0.22);
  border-color: var(--accent);
}
.token-chip-nav-label {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.token-chip-nav strong {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.usage-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.usage-table .tok-credit { color: var(--ok); font-weight: 700; }
.usage-table .tok-debit { color: var(--error); font-weight: 700; }

/* Photo crop modal */
.crop-dialog {
  width: min(420px, 100%);
}
.crop-stage {
  position: relative;
  width: 300px;
  height: 300px;
  max-width: 100%;
  margin: 0.75rem auto;
  overflow: hidden;
  border-radius: 12px;
  background: #0b1220;
  cursor: grab;
  touch-action: none;
  user-select: none;
  border: 1px solid var(--border);
}
.crop-stage:active { cursor: grabbing; }
.crop-stage #crop-image {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  transform-origin: 0 0;
  pointer-events: none;
  -webkit-user-drag: none;
}
.crop-frame {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.9),
              0 0 0 9999px rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  pointer-events: none;
}
.crop-zoom-label {
  display: block;
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}
#crop-zoom {
  width: 100%;
  margin: 0.35rem 0 0;
  accent-color: var(--accent);
}

.meta { color: var(--muted); font-size: 0.88rem; }
.invite-url {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.82rem;
  word-break: break-all;
  background: var(--bg);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.footer {
  margin-top: 3rem; padding: 1.5rem;
  text-align: center; color: var(--muted); font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; }
.inline-form > div { flex: 1; min-width: 160px; }
.inline-form .btn { margin-bottom: 0.85rem; }

@media (max-width: 640px) {
  .table { display: block; overflow-x: auto; }
  .hero { padding-top: 2.5rem; }
}
