/* ============================================================================
   Lintel — admin design system
   Grounded in the subject: a lintel is the stone that bears weight above a door.
   The product is about thresholds — teaching HELD until standing is attested,
   then OPENED. The visual language is architectural and record-keeping, not
   decorative: hairline rules, an inscription serif, monospace for provenance.
   ========================================================================== */

:root {
  /* Paper & ink — cooler and more architectural than cream; deliberately not
     the warm-cream/terracotta AI-default. */
  --paper:      #F5F4F1;   /* stone paper */
  --paper-2:    #FBFAF9;   /* raised surface */
  --ink:        #161A2E;   /* doorway shadow — primary */
  --ink-soft:   #3A3E52;
  --muted:      #6B6E7C;
  --rule:       #E2E0DA;   /* hairline */
  --rule-2:     #D0CDC5;

  /* State — the threshold. Brass = opened/attested. Slate = held (never red). */
  --brass:      #8A6D3B;
  --brass-soft: #F0E9DB;
  --held:       #5B5570;
  --held-soft:  #ECEAF0;
  --ok:         #3B6152;
  --ok-soft:    #E4EDE7;

  --serif: "Iowan Old Style", "Palatino Linotype", "Palatino", "Georgia", serif;
  --sans:  ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono:  ui-monospace, "SF Mono", "JetBrains Mono", "Menlo", "Consolas", monospace;

  --rail: 248px;
  --maxc: 960px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- App shell: quiet left rail + content ------------------------------- */
.app { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }

.rail {
  background: var(--ink);
  color: #C9CAD4;
  padding: 22px 0 30px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.rail .brand {
  display: flex; align-items: baseline; gap: 9px;
  padding: 0 22px 4px;
  font-family: var(--serif);
  font-size: 21px; font-weight: 600; letter-spacing: .01em; color: #fff;
}
.rail .brand .mark { /* the lintel: a stone bearing weight — a capped vertical */
  display: inline-block; width: 15px; height: 15px; position: relative;
}
.rail .brand .mark::before { content: ""; position: absolute; left: 2px; top: 0; width: 11px; height: 3px; background: var(--brass); }
.rail .brand .mark::after  { content: ""; position: absolute; left: 4px; top: 3px; width: 3px; height: 12px; background: #6E7189; }
.rail .inst {
  padding: 2px 22px 20px; font-size: 12.5px; color: #888CA0;
  border-bottom: 1px solid #262B44; margin-bottom: 12px;
}

.rail nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; }
.rail .group { padding: 16px 10px 6px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .13em; text-transform: uppercase; color: #6E7189; }
.rail nav a {
  color: #C9CAD4; padding: 7px 10px; border-radius: 4px; font-size: 14px;
  display: flex; align-items: center; gap: 9px;
}
.rail nav a:hover { background: #222741; color: #fff; text-decoration: none; }
.rail nav a.active { background: #262B47; color: #fff; }
.rail nav a.active::before { content: ""; width: 3px; height: 15px; background: var(--brass); border-radius: 2px; margin-left: -10px; margin-right: 7px; }
.rail nav a.help-link { margin-top: 12px; border-top: 1px solid #262B47; padding-top: 13px; color: #E7E8EE; }
.rail nav a.help-link .help-ico { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--brass); color: var(--brass); font-size: 11px; font-weight: 700; line-height: 1; flex: 0 0 auto; }
.rail nav a.help-link:hover .help-ico { border-color: #fff; color: #fff; }
.rail .foot { margin-top: auto; padding: 16px 22px 0; font-size: 12px; color: #6E7189; }

/* ---- Content ------------------------------------------------------------ */
.content { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 40px; height: 62px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.topbar .crumbs { font-size: 13px; color: var(--muted); font-family: var(--mono); }
.topbar .crumbs a { color: var(--muted); }
.topbar .crumbs .sep { margin: 0 7px; opacity: .5; }
.topbar .who { font-size: 13px; color: var(--muted); }
.topbar .who form { display: inline; }
.topbar .who button { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; margin-left: 14px; }
.topbar .who button:hover { color: var(--ink); text-decoration: underline; }

.main { max-width: var(--maxc); padding: 34px 40px 80px; }

/* Page header */
.page-head { margin-bottom: 26px; }
.page-head .eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--brass); margin-bottom: 8px; }
.page-head h1 { font-family: var(--serif); font-size: 30px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 6px; }
.page-head .lede { color: var(--muted); font-size: 15px; max-width: 60ch; margin: 0; }

/* Sections */
.section { margin-top: 38px; }
.section > h2 { font-family: var(--serif); font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.section > .hint { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }

/* ---- Tables: the register look ------------------------------------------ */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead th {
  text-align: left; font-family: var(--mono); font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); font-weight: 500;
  padding: 0 16px 10px 0; border-bottom: 1px solid var(--rule-2);
}
.table tbody td { padding: 12px 16px 12px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table tbody tr:hover td { background: var(--paper-2); }
.table .mono { font-family: var(--mono); font-size: 13px; }
.table .empty td { color: var(--muted); padding: 22px 0; border-bottom: 0; }

/* ---- Threshold badges: open / held / neutral ---------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: .04em; padding: 3px 9px; border-radius: 3px; text-transform: uppercase; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.badge.open  { background: var(--brass-soft); color: #6B5325; }
.badge.open::before  { background: var(--brass); }
.badge.held  { background: var(--held-soft); color: #4A4560; }
.badge.held::before  { background: var(--held); }
.badge.ok    { background: var(--ok-soft); color: #2C4A3D; }
.badge.ok::before    { background: var(--ok); }
.badge.flat  { background: #EDEBE6; color: var(--muted); }
.badge.flat::before  { background: var(--muted); }

/* ---- Cards / list rows (used sparingly, rules not shadows) -------------- */
.panel { border: 1px solid var(--rule); border-radius: 5px; background: var(--paper-2); padding: 20px 22px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { border: 1px solid var(--rule); border-radius: 5px; background: var(--paper-2); padding: 15px 18px; margin-bottom: 10px; }
.rows li .title { font-size: 15px; }
.rows li .meta { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* Pagination control (admin + console lists) */
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 22px 0 4px; }
.pager-btn { font-size: 13px; padding: 7px 13px; border: 1px solid var(--rule-2, #ccc); border-radius: 6px; color: var(--ink); text-decoration: none; background: var(--paper); }
.pager-btn:hover { border-color: var(--muted); text-decoration: none; }
.pager-btn.is-off { opacity: .4; pointer-events: none; }
.pager-at { font-size: 13px; color: var(--muted); }

/* Rendered rich-text (the sanitised institution About, and any future HTML prose).
   Long URLs/words break rather than forcing the page wider. */
.prose { line-height: 1.65; overflow-wrap: anywhere; }
.prose p { margin: 0 0 12px; }
.prose p:last-child { margin-bottom: 0; }
.prose h3 { font-family: var(--serif); font-size: 18px; margin: 18px 0 6px; }
.prose h4 { font-family: var(--serif); font-size: 15px; margin: 16px 0 6px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 2px 0; }
.prose blockquote { margin: 0 0 12px; padding-left: 14px; border-left: 3px solid var(--rule-2); color: var(--muted); }
.prose a { color: var(--brass); }

/* The threshold rule — a thin bar marking open vs held content. The signature. */
.thr { border-left: 3px solid var(--rule-2); padding-left: 16px; }
.thr.is-open { border-left-color: var(--brass); }
.thr.is-held { border-left-color: var(--held); }

/* ---- Forms -------------------------------------------------------------- */
.field { margin: 0 0 15px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.field .note { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
/* Every text-like input shares the app's styling. Listing the input types (rather
   than a bare `input`) keeps checkbox/radio/file/range alone — but it must cover
   number, tel, search, url and date, which carry the app's own numeric/▾ fields
   (fees, gradebook, quizzes, payouts) and were previously left browser-default. */
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=search], input[type=url], input[type=date],
input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; font-family: var(--sans); font-size: 14.5px;
  border: 1px solid var(--rule-2); border-radius: 4px; background: var(--paper-2); color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--brass); background: #fff; outline: none; }
.form-narrow { max-width: 440px; }

.btn { display: inline-flex; align-items: center; gap: 7px; font-family: var(--sans); font-size: 14px; font-weight: 500; padding: 9px 16px; border-radius: 4px; border: 1px solid var(--ink); background: var(--ink); color: #fff; cursor: pointer; }
.btn:hover { background: #23283F; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule-2); }
.btn.ghost:hover { background: var(--paper-2); border-color: var(--muted); }
.btn.small { padding: 6px 11px; font-size: 13px; }

/* ---- Notices ------------------------------------------------------------ */
.notice { padding: 12px 15px; border-radius: 4px; font-size: 14px; margin-bottom: 18px; border-left: 3px solid; }
.notice.err  { background: var(--held-soft); border-color: var(--held); color: #443F58; }
.notice.info { background: var(--brass-soft); border-color: var(--brass); color: #5F4A20; }

/* ---- Inline stat strip (dashboard) -------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.stats .stat { background: var(--paper-2); padding: 18px 20px; }
.stats .stat .n { font-family: var(--serif); font-size: 27px; font-weight: 600; line-height: 1; }
.stats .stat .l { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-top: 8px; }

.quiet { color: var(--muted); }
.mono { font-family: var(--mono); }

/* ---- Responsive: rail collapses to a top bar --------------------------- */
/* Mobile nav controls — inert on desktop, activated in the breakpoint below. */
.rail-toggle { display: none; }
.rail-scrim  { display: none; }

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

  /* The sidebar becomes an off-canvas drawer, slid in over the content. */
  .rail {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 264px; max-width: 82vw; height: 100vh; z-index: 60;
    transform: translateX(-100%); transition: transform .22s ease, visibility .22s ease;
    visibility: hidden; /* keep the closed drawer out of the tab order / a11y tree */
  }
  body.nav-open .rail { transform: translateX(0); visibility: visible; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  body.nav-open { overflow: hidden; } /* lock page scroll while the drawer is open */

  /* Dimmed backdrop behind the open drawer; tap to close. */
  .rail-scrim { display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(20,24,40,.5); opacity: 0; pointer-events: none; transition: opacity .22s ease; }
  body.nav-open .rail-scrim { opacity: 1; pointer-events: auto; }

  /* Hamburger in the (already sticky) topbar. */
  .rail-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; flex: none; margin-right: 4px;
    background: none; border: 1px solid var(--rule-2); border-radius: 7px;
    font-size: 19px; line-height: 1; color: var(--ink); cursor: pointer;
  }
  .rail-toggle:hover { background: var(--paper-2); }

  .topbar { padding: 0 16px; gap: 10px; }
  .topbar .crumbs { display: none; }   /* the page's own heading carries context */
  .topbar .who { font-size: 12px; }
  .topbar .who .uname { display: none; } /* signed-in name is redundant on small screens */
  .topbar .who a { margin-right: 10px; }

  .main { padding: 22px 16px 64px; }

  /* Wide tables scroll horizontally instead of forcing the page wider. */
  .table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  /* Forms never overflow their card. */
  input, select, textarea { max-width: 100%; }
  /* 16px prevents iOS Safari from zooming in when a field is focused — the single
     most common "the form jumps around on my phone" complaint. Applies to every
     text-like control on small screens. */
  input, select, textarea { font-size: 16px; }
  .card { padding: 14px 15px; }
}

/* ---- Phones (≤560px): stop horizontal overflow -------------------------- */
/* The admin/public views lay out toolbars and field+button groups with inline
   `display:flex`. On a narrow screen a non-wrapping row of two 220px children
   overflows the viewport. These rows never set flex-wrap, so setting it from the
   stylesheet makes them stack instead — without editing ~35 templates. A row that
   deliberately opts out (flex-wrap in its own style) is excluded and untouched. */
@media (max-width: 560px) {
  [style*="display:flex"]:not([style*="flex-wrap"]) { flex-wrap: wrap; }

  /* Media and embeds never push the page wider than the screen. */
  .main img, .main video, .main iframe { max-width: 100%; }
  /* Long code/preformatted content scrolls itself rather than the page. */
  .main pre { overflow-x: auto; }
  /* Oversized page titles come back to a phone-friendly size. !important because
     several views set an inline font-size on the h1, which would otherwise win. */
  .page-head h1 { font-size: 22px !important; }
  .main { padding: 20px 16px 64px; }

  /* Public pages use the .pub-main layout, not .main, so they missed the overflow
     guards above. Give them the same protection: a tighter gutter, media that
     never pushes the page wide, long words/URLs that break, and buttons that wrap
     instead of overflowing (a long "Sign in to <institution>" label is inline-flex
     and would otherwise force horizontal scroll on a phone). */
  .pub-main { padding: 30px 18px; }
  .pub-main img, .pub-main video, .pub-main iframe { max-width: 100%; height: auto; }
  .pub-main pre { overflow-x: auto; }
  .pub-wide, .pub-card { overflow-wrap: anywhere; }
  .btn { white-space: normal; max-width: 100%; }
}

/* Quiz authoring */
.q-block{padding:14px 16px}
.q-prompt{font-size:15px;line-height:1.5;margin-bottom:8px}
.q-num{color:var(--muted,#777);font-weight:600;margin-right:2px}
.q-answers{list-style:none;margin:8px 0 0;padding:0;font-size:14px}
.q-answers li{padding:2px 0;color:#555}
.q-answers li.correct{color:#25473A;font-weight:600}
.q-optrow{display:flex;gap:10px;align-items:center;margin:6px 0}
.q-optrow input[type=text]{flex:1}
.q-optck{white-space:nowrap;font-size:13px;color:#555;display:flex;align-items:center;gap:5px}
.q-opt{display:flex;align-items:center;gap:8px;font-size:14px}
.q-match{display:flex;gap:10px;align-items:center;margin:6px 0}
.q-match input{flex:1}

/* Card + back-link (used by quiz authoring and the invite page) */
.card{background:var(--paper-2);border:1px solid var(--rule);border-radius:4px;padding:16px 18px;margin:10px 0}
.back{color:var(--muted);font-size:13px}
.back:hover{color:var(--ink)}

/* Course cover-image picker (authoring) */
.cover-picker{display:flex;flex-wrap:wrap;gap:10px}
.cover-opt{position:relative;cursor:pointer;border:2px solid var(--rule,#E3E0D9);border-radius:8px;overflow:hidden;width:150px;height:84px;display:flex;align-items:center;justify-content:center;background:#F5F4F1}
.cover-opt img{width:100%;height:100%;object-fit:cover;display:block}
.cover-opt input{position:absolute;opacity:0;pointer-events:none}
.cover-opt.sel{border-color:var(--brass,#8C6E33);box-shadow:0 0 0 2px rgba(140,110,51,.2)}
.cover-opt .cover-none{font-size:12px;color:#6E6B63}
.cover-opt:has(input:checked){border-color:var(--brass,#8C6E33);box-shadow:0 0 0 2px rgba(140,110,51,.2)}

/* ---- Per-page help ("?" in the top bar; panel is a native <dialog>) ---- */
.pagehelp-btn{ flex:0 0 auto; margin-right:auto; margin-left:14px; width:24px; height:24px; border-radius:50%; border:1.5px solid var(--rule-2); background:none; color:var(--muted); font-size:13px; font-weight:700; line-height:1; cursor:pointer; display:inline-flex; align-items:center; justify-content:center; }
.pagehelp-btn:hover{ border-color:var(--brass); color:var(--ink); }
.pagehelp-btn-c{ border-color:#3a4060; color:#C9A567; }
.pagehelp-btn-c:hover{ border-color:#C9A567; color:#fff; }
dialog.pagehelp{ width:min(92vw,440px); border:1px solid var(--rule); border-radius:12px; padding:26px 26px 22px; background:var(--paper-2); color:var(--ink); box-shadow:0 24px 60px rgba(0,0,0,.22); }
dialog.pagehelp::backdrop{ background:rgba(20,24,40,.42); }
.pagehelp-close{ position:absolute; top:8px; right:12px; margin:0; }
.pagehelp-close button{ background:none; border:0; font-size:26px; line-height:1; color:var(--muted); cursor:pointer; padding:2px 6px; }
.pagehelp-close button:hover{ color:var(--ink); }
.pagehelp-eyebrow{ font-family:var(--mono); font-size:10.5px; letter-spacing:.14em; text-transform:uppercase; color:var(--brass); margin-bottom:6px; }
dialog.pagehelp h2{ margin:0 0 10px; font-size:19px; }
.pagehelp-what{ margin:0 0 15px; font-size:14px; line-height:1.6; }
.pagehelp-lbl{ font-size:11px; letter-spacing:.08em; text-transform:uppercase; color:var(--muted); font-weight:600; margin:0 0 6px; }
.pagehelp-actions{ margin:0 0 15px; padding-left:18px; }
.pagehelp-actions li{ margin:5px 0; font-size:13.5px; line-height:1.5; }
.pagehelp-tip{ font-size:13px; line-height:1.55; color:var(--muted); border-left:2px solid var(--brass); padding:2px 0 2px 12px; margin:0 0 15px; }
.pagehelp-more{ margin:0; font-size:13px; }
.pagehelp-more a{ color:var(--brass); }
/* Platform console wears the dark palette. */
dialog.pagehelp.pagehelp-dark{ background:#1b2036; color:#EDECE9; border-color:#2a3050; }
dialog.pagehelp.pagehelp-dark .pagehelp-eyebrow,
dialog.pagehelp.pagehelp-dark .pagehelp-more a{ color:#C9A567; }
dialog.pagehelp.pagehelp-dark .pagehelp-what{ color:#C9CAD4; }
dialog.pagehelp.pagehelp-dark .pagehelp-lbl{ color:#8E91A3; }
dialog.pagehelp.pagehelp-dark .pagehelp-close button{ color:#9A9CAC; }
dialog.pagehelp.pagehelp-dark .pagehelp-close button:hover{ color:#fff; }
dialog.pagehelp.pagehelp-dark .pagehelp-tip{ color:#9A9CAC; border-left-color:#C9A567; }
