:root {
  --paper: #f4f1ea;
  --paper-deep: #ebe6db;
  --surface: #fffdf9;
  --ink: #1b1a17;
  --ink-soft: #4a4740;
  --muted: #7a756a;
  --line: #e2ddd1;
  --line-strong: #cfc8b8;
  --accent: #2443b0;
  --accent-ink: #1a3290;
  --accent-wash: #e6eaf8;
  --danger: #b03a2e;
  --danger-wash: #fbece9;
  --ok: #2d6a45;
  --ok-wash: #e7f2ea;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgb(40 32 16 / 5%), 0 4px 16px rgb(40 32 16 / 5%);
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 15px/1.55 var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, .serif { font-family: var(--serif); font-weight: 500; letter-spacing: -0.01em; }
h1 { font-size: 2.1rem; line-height: 1.15; margin: 0; }
h2 { font-size: 1.4rem; line-height: 1.25; margin: 0 0 .9rem; }
h3 { font-size: .95rem; margin: 0; font-weight: 600; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.caps { text-transform: uppercase; letter-spacing: .02em; }
.meta { color: var(--muted); font-size: .86rem; margin: 0; font-weight: 400; font-family: var(--sans); letter-spacing: 0; }
.eyebrow { color: var(--muted); font-size: .8rem; margin: 0 0 .2rem; }
.empty { color: var(--muted); }
.crumbs { color: var(--muted); font-size: .86rem; margin: 0 0 .35rem; }
.crumbs a { color: var(--ink-soft); }
.crumbs span { margin: 0 .25rem; color: var(--line-strong); }

.mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: italic 500 15px/1 var(--serif);
  margin-right: .6rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .7rem 1.5rem;
  background: rgb(255 253 249 / 88%);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; font-weight: 600; color: var(--ink); }
.brand:hover { color: var(--ink); }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { color: var(--ink-soft); padding: .35rem .7rem; border-radius: var(--radius-sm); }
.topbar nav a:hover { background: var(--paper); color: var(--ink); }
.who { margin-left: auto; display: flex; align-items: center; gap: .6rem; color: var(--ink-soft); font-size: .9rem; }
.who form { margin: 0 0 0 .4rem; }
.promo-switch { margin: 0; }
.promo-switch select {
  height: 2.1rem;
  padding: 0 2rem 0 .8rem;
  border-radius: 999px;
  background-color: var(--paper);
  font-weight: 600;
}

.main { max-width: 960px; margin: 0 auto; padding: 2.25rem 1.5rem 5rem; }
.main.wide { max-width: 1320px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.page-head .meta { margin-top: .35rem; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.stats { display: flex; gap: 1.25rem; margin-top: .6rem; color: var(--ink-soft); font-size: .88rem; align-items: center; flex-wrap: wrap; }
.stats > span { display: inline-flex; align-items: center; gap: .55rem; }

.field { display: flex; flex-direction: column; gap: .35rem; font-size: .86rem; }
.field > span { color: var(--ink-soft); font-weight: 500; }

input, select, textarea, button, .button {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
input, select, textarea { padding: .55rem .75rem; min-width: 0; transition: border-color .15s, box-shadow .15s; }
input, select { height: 2.6rem; }
input[type=checkbox] { height: auto; accent-color: var(--accent); width: 1rem; height: 1rem; }
select {
  appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16' fill='none' stroke='%237a756a' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
}
textarea { width: 100%; resize: vertical; line-height: 1.6; }
input::placeholder, textarea::placeholder { color: #a9a395; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  height: 2.6rem;
  padding: 0 1rem;
  font-weight: 600;
  font-size: .9rem;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s, border-color .15s, transform .1s;
}
button:hover, .button:hover { border-color: var(--ink-soft); color: var(--ink); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: .6; cursor: progress; transform: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
button.link {
  height: auto;
  border: 0;
  background: none;
  padding: 0;
  font-weight: 500;
  color: var(--accent);
}
button.link:hover { color: var(--accent-ink); text-decoration: underline; }
button.link.danger { color: var(--danger); background: none; }
.button.icon { width: 2.3rem; height: 2.3rem; padding: 0; }
.button.disabled { opacity: .35; pointer-events: none; }

.busy { display: none; align-items: center; gap: .45rem; }
.htmx-request .idle { display: none; }
.htmx-request .busy { display: inline-flex; }
.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.row-end { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; flex-wrap: wrap; }
.inline-form { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-top: 1rem; }
.inline { display: inline; margin: 0; }

.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  margin: 0 0 1.25rem;
  font-size: .92rem;
  border-left: 3px solid;
}
.alert.error { color: var(--danger); background: var(--danger-wash); }
.alert.ok { color: var(--ok); background: var(--ok-wash); }

.avatar {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.avatar.sm { width: 1.75rem; height: 1.75rem; font-size: .66rem; }
.avatar.lg { width: 3rem; height: 3rem; font: 500 1.15rem/1 var(--serif); background: var(--accent-wash); color: var(--accent); }
.avatar.filled { background: var(--accent-wash); color: var(--accent); }

.progress { display: inline-block; width: 72px; height: 5px; border-radius: 999px; background: var(--paper-deep); overflow: hidden; vertical-align: middle; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

.auth-split { display: grid; grid-template-columns: minmax(320px, 5fr) 7fr; min-height: 100vh; }
.auth-side {
  background: var(--accent);
  color: #fff;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 31px, rgb(255 255 255 / 7%) 31px 32px);
}
.brand.light { color: #fff; margin: 0; }
.brand.light .mark { background: #fff; color: var(--accent); }
.auth-quote .serif { font-size: 2rem; line-height: 1.2; margin: 0 0 1rem; max-width: 18ch; }
.auth-promo { margin: 0; opacity: .8; font-size: .92rem; }
.auth-main { display: grid; place-items: center; padding: 2.5rem 1.5rem; }
.auth { width: 100%; max-width: 400px; }
.auth h1 { margin-bottom: .4rem; }
.auth .lede { color: var(--muted); margin: 0 0 1.75rem; }
.auth button.primary { width: 100%; margin-top: .4rem; }
.auth .aside { margin-top: 1.5rem; color: var(--muted); text-align: center; }

.block, .session, .empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  margin-top: 1.25rem;
  box-shadow: var(--shadow);
}
.danger-zone { border-color: #ecd0ca; box-shadow: none; background: transparent; }
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-state p { color: var(--muted); max-width: 46ch; margin: 0 auto 1.25rem; }

.session h2 { display: flex; align-items: baseline; gap: .75rem; }
.tiles { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .75rem; }
.tiles a {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--paper);
  transition: border-color .15s, background-color .15s, transform .15s;
}
.tiles a:hover { border-color: var(--accent); background: var(--surface); transform: translateY(-1px); }
.tiles strong { font-size: 1.05rem; }
.tiles .progress { width: 100%; margin-top: .35rem; }

.tabs { display: flex; gap: .25rem; margin-bottom: 1.75rem; background: var(--paper-deep); padding: .25rem; border-radius: 999px; width: fit-content; }
.tabs a { color: var(--ink-soft); padding: .4rem 1rem; border-radius: 999px; font-weight: 500; font-size: .9rem; }
.tabs a[aria-current] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 1.25rem; box-shadow: var(--shadow); overflow: hidden; }
th, td { text-align: left; padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; background: var(--paper); }
tr:last-child td { border-bottom: 0; }
.right { text-align: right; }
.row-form { display: flex; gap: .5rem; align-items: center; }
.row-form input { flex: 1; height: 2.3rem; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; }
.checks label { display: flex; gap: .35rem; align-items: center; }

.tag { font-size: .72rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--accent-wash); color: var(--accent); vertical-align: middle; }

.list { list-style: none; padding: 0; margin: 0 0 .5rem; }
.list li { display: flex; gap: .75rem; align-items: baseline; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li form { margin-left: auto; }

.provider-form { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.provider-form .row-end { grid-column: 1 / -1; }

.workspace { display: grid; grid-template-columns: 290px 1fr; gap: 1.5rem; align-items: start; }

.students {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 6rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.students-search { padding: .6rem; border-bottom: 1px solid var(--line); }
.students-search input { width: 100%; height: 2.3rem; background: var(--paper); border-color: transparent; }
.students ol { list-style: none; margin: 0; padding: .4rem; overflow: auto; }
.students a { display: flex; align-items: center; gap: .65rem; padding: .45rem .55rem; border-radius: var(--radius-sm); color: var(--ink); font-size: .9rem; }
.student-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.students a:hover { background: var(--paper); color: var(--ink); }
.students a[aria-current] { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.students a[aria-current] .avatar { background: var(--accent); color: #fff; }
.count { min-width: 1.4rem; text-align: center; padding: 0 .35rem; border-radius: 999px; background: var(--paper-deep); color: var(--ink-soft); font-size: .74rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.check { display: inline-grid; place-items: center; width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--ok-wash); color: var(--ok); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem 1.75rem 1.75rem; min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.panel-head h2 { margin: 0; font-size: 1.65rem; }
.panel-head .caps { font-size: .85em; }
.stepper { margin-left: auto; display: flex; gap: .4rem; }

.notes ol { list-style: none; margin: 0; padding: 0; }
.note { display: flex; gap: .8rem; padding: .75rem 0; border-top: 1px solid var(--line); }
.note:first-child { border-top: 0; }
.note .avatar { margin-top: .1rem; }
.note-content { flex: 1; min-width: 0; }
.note-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-meta { margin: .15rem 0 0; font-size: .8rem; color: var(--muted); display: flex; gap: 1rem; flex-wrap: wrap; }
.note-actions { display: inline-flex; gap: .9rem; opacity: 0; transition: opacity .15s; }
.note-actions button { font-size: .8rem; }
.note:hover .note-actions, .note:focus-within .note-actions { opacity: 1; }
@media (hover: none) { .note-actions { opacity: 1; } }
.notes-empty { padding: 1.25rem; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); text-align: center; }
.notes-empty p { margin: 0 0 .25rem; }

.composer { display: flex; gap: .5rem; margin-top: 1rem; }
.composer input { flex: 1; height: 2.9rem; font-size: 1rem; background: var(--paper); border-color: transparent; }
.composer input:focus { background: var(--surface); }
.composer button { height: 2.9rem; }
.composer.edit { margin: 0; flex: 1; }
.composer.edit input { height: 2.5rem; font-size: .95rem; }
.composer.edit button { height: 2.5rem; }
.note-edit { padding: .5rem 0; }
.hint { margin: .5rem 0 0; color: var(--muted); font-size: .78rem; }

.synthesis { margin-top: 1.75rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.section-head .meta { margin-top: .2rem; max-width: 60ch; }
.synthesis h3 { font: 500 1.3rem/1.2 var(--serif); }
.paper {
  background: var(--paper);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1.25rem 1rem;
  border: 1px solid var(--line);
}
.paper textarea {
  border: 0;
  background: transparent;
  padding: 0;
  font: 1.12rem/1.65 var(--serif);
  color: var(--ink);
  box-shadow: none;
  field-sizing: content;
  min-height: 5lh;
}
.paper-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: .75rem; flex-wrap: wrap; }
.paper .save { display: none; }
.paper.dirty .save { display: inline-flex; background: var(--accent); border-color: var(--accent); color: #fff; }
.paper.dirty .paper-foot .meta { visibility: hidden; }

.print header { margin-bottom: 2rem; display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; }
.print-student { padding: 1.1rem 0; border-top: 1px solid var(--line); break-inside: avoid; }
.print-student h2 { font-size: 1.15rem; margin-bottom: .35rem; }
.print-student p { margin: 0; font: 1.05rem/1.6 var(--serif); }
.print-student ul { margin: 0; padding-left: 1.2rem; }

@media (max-width: 860px) {
  .auth-split { grid-template-columns: 1fr; }
  .auth-side { padding: 1.5rem; min-height: auto; }
  .auth-quote .serif { font-size: 1.4rem; margin: 2rem 0 .5rem; }
  .workspace { grid-template-columns: 1fr; }
  .students { position: static; max-height: 45vh; }
  .provider-form { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  h1 { font-size: 1.7rem; }
  .main { padding: 1.5rem 1rem 4rem; }
  .topbar { padding: .6rem 1rem; gap: .75rem; }
  .who-name { display: none; }
  .row { grid-template-columns: 1fr; }
  .panel { padding: 1.1rem; }
  .panel-head h2 { font-size: 1.3rem; }
  input, select, textarea { font-size: 16px; }
  .hint { display: none; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  td { border: 0; padding: .35rem 1rem; }
  tr { border-bottom: 1px solid var(--line); padding: .5rem 0; }
  .right { text-align: left; }
}

@media print {
  body { background: #fff; font-size: 11pt; }
  .topbar, .no-print { display: none; }
  .main { padding: 0; max-width: none; }
}

.badge { display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem; padding: 0 .35rem; margin-left: .3rem; border-radius: 999px; background: var(--accent); color: #fff; font-size: .7rem; font-weight: 700; }
.pending { border-color: #c9d3f2; background: #f8f9fe; }
.pending .list li { align-items: center; }
.pending-actions { margin-left: auto; display: flex; gap: 1rem; align-items: center; }
.pending .list li form { margin: 0; }
.pending-actions button.primary { height: 2.2rem; }
.user-actions { white-space: nowrap; }
.user-actions form + form { margin-left: 1rem; }
.forgot { align-self: flex-end; font-size: .82rem; margin-top: -.1rem; }
.button.wide { width: 100%; }
