/* Levelmath stylesheet — Nunito only, squared-paper palette, blue ink.
   nunito.css (self-hosted font faces) is linked separately from base.html.j2. */

:root {
  --paper: #f4f7fa;
  --grid: #dde6ef;
  --rule: #c9d6e4;
  --card: #ffffff;
  --ink: #15274a;
  --ink-soft: #5c6d88;
  --ink-faint: #91a0b5;
  --blue: #2b5bd7;
  --blue-soft: #e4ebfb;
  --red: #d63b2f;
  --red-soft: #fbe7e4;
  --green: #238f5f;
  --green-soft: #e0f3ea;
  --amber: #9a6700;
  --amber-soft: #fdf1dc;
  --radius: 8px;
  --radius-lg: 14px;
  --font: "Nunito", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.15; font-weight: 800; }
h1 { font-size: 1.9rem; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--rule);
}
.topbar__inner {
  max-width: 1120px; margin: 0 auto; padding: 0 1.25rem;
  display: flex; align-items: center; gap: 1.5rem; min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--ink); font-weight: 900; font-size: 1.2rem; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; fill: var(--blue); transform: rotate(-12deg); }
.nav { display: flex; gap: 0.25rem; margin: 0; padding: 0; list-style: none; }
.nav a {
  display: inline-block; padding: 0.4rem 0.8rem; border-radius: 999px;
  color: var(--ink-soft); font-weight: 700;
}
.nav a:hover { color: var(--ink); background: var(--paper); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--blue); background: var(--blue-soft); }
.nav details { position: relative; }
.nav summary { list-style: none; cursor: pointer; display: inline-block; padding: 0.4rem 0.8rem; border-radius: 999px; color: var(--ink-soft); font-weight: 700; }
.nav summary::-webkit-details-marker { display: none; }
.nav summary::after { content: ""; display: inline-block; margin-left: 0.4rem; border: 4px solid transparent; border-top-color: currentColor; vertical-align: 1px; }
.nav details[open] summary, .nav summary:hover { color: var(--ink); background: var(--paper); }
.nav .menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 10; min-width: 180px;
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 0.35rem; box-shadow: 0 8px 24px rgba(21, 39, 74, 0.10);
}
.nav .menu a { display: block; border-radius: 6px; padding: 0.4rem 0.7rem; }
.nav .menu a strong { color: var(--ink); }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.search { position: relative; }
.search input {
  width: 240px; padding: 0.45rem 0.75rem 0.45rem 2.1rem;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--paper);
  font: inherit; color: var(--ink);
}
.search input::placeholder { color: var(--ink-faint); }
.search svg { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; fill: var(--ink-faint); }
.logout { background: none; border: 0; font: inherit; font-weight: 700; color: var(--ink-soft); cursor: pointer; padding: 0.4rem 0.6rem; border-radius: 999px; }
.logout:hover { background: var(--paper); color: var(--ink); }
.logout span { color: var(--ink); }

/* ---------- page ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head .kicker { color: var(--ink-soft); font-weight: 700; margin-bottom: 0.2rem; }
.page-head .kicker a { color: inherit; }
.grid { display: grid; gap: 1.25rem; }
.grid--2-1 { grid-template-columns: 2fr 1fr; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) { .grid--2-1, .grid--3 { grid-template-columns: 1fr; } }

.panel {
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem; margin-bottom: 1.25rem;
}
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.panel__head h2 { font-size: 1.05rem; }
.panel__head .meta { color: var(--ink-soft); font-size: 0.875rem; }
.panel--tight { padding: 0; overflow: hidden; }
.panel--tight .panel__head { padding: 1rem 1.5rem 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 1rem; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 800; cursor: pointer; line-height: 1.2; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover { background: #1f49b8; }
.btn--secondary { background: var(--card); color: var(--ink); border-color: var(--rule); }
.btn--secondary:hover { background: var(--paper); }
.btn--ghost { background: transparent; color: var(--blue); padding-left: 0.5rem; padding-right: 0.5rem; }
.btn--ghost:hover { background: var(--blue-soft); }
.btn--danger { background: transparent; color: var(--red); border-color: var(--rule); }
.btn--danger:hover { background: var(--red-soft); }
.btn--sm { padding: 0.3rem 0.7rem; font-size: 0.8125rem; }
.btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.field label { font-weight: 700; font-size: 0.875rem; color: var(--ink-soft); }
.field input[type="text"], .field input[type="password"], .field select {
  padding: 0.55rem 0.75rem; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--card); font: inherit; color: var(--ink);
}
.field input:focus, .field select:focus { border-color: var(--blue); outline: 3px solid var(--blue-soft); }
.field--row { flex-direction: row; align-items: center; gap: 0.5rem; }
.field--row label { color: var(--ink); font-weight: 600; }
.form-inline { display: flex; align-items: flex-end; gap: 0.75rem; flex-wrap: wrap; }
.form-inline .field { margin-bottom: 0; flex: 1 1 160px; }
.form-inline .btn { margin-bottom: 0; }
.help { color: var(--ink-faint); font-size: 0.8125rem; margin-top: 0.25rem; }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th {
  text-align: left; white-space: nowrap; font-weight: 700; font-size: 0.8125rem; color: var(--ink-soft);
  padding: 0.6rem 1.5rem; border-bottom: 1px solid var(--rule);
}
.table td { padding: 0.65rem 1.5rem; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--paper); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions a, .table .actions button {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border-radius: 50%; border: 0; background: transparent; color: var(--ink-soft); cursor: pointer;
}
.table .actions a:hover, .table .actions button:hover { background: var(--blue-soft); color: var(--blue); text-decoration: none; }
.table .actions .danger:hover { background: var(--red-soft); color: var(--red); }
.table .actions svg { width: 16px; height: 16px; fill: currentColor; }
.table a.name { color: var(--ink); font-weight: 700; }
/* below ~960px the cells tighten up before the table has to scroll */
@media (max-width: 960px) {
  .table th, .table td { padding-left: 0.75rem; padding-right: 0.75rem; }
  .table th:first-child, .table td:first-child { padding-left: 1.25rem; }
  .table th:last-child, .table td:last-child { padding-right: 1.25rem; }
}

/* level number + bar (+ sheet title) as a small number line on every row.
   A grid, not flex: the number and the bar keep their width, the title gets
   at least 12rem so it wraps in at most a line or two. */
.level { --bar: 120px; display: grid; grid-template-columns: 4ch var(--bar); align-items: center; gap: 0.6rem; }
.level--titled { grid-template-columns: 4ch var(--bar) minmax(12rem, 1fr); }
.level__num { font-weight: 900; font-variant-numeric: tabular-nums; text-align: right; } /* 4ch fits "10.0" so the bars line up */
.level__bar { position: relative; width: 100%; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.level__bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--blue); border-radius: 3px; }
.level__sheet { color: var(--ink-soft); font-size: 0.875rem; }
@media (max-width: 960px) { .level { --bar: 80px; } }

.tag { display: inline-block; white-space: nowrap; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.8125rem; font-weight: 700; background: var(--paper); color: var(--ink-soft); border: 1px solid var(--grid); }
.tag--yes { background: var(--green-soft); color: var(--green); border-color: transparent; }

/* ---------- number line (the dashboard hero) ---------- */
.numberline { padding: 1.5rem 1.5rem 1rem; }
.numberline__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 0.5rem; }
.numberline__legend { display: flex; gap: 1.25rem; font-size: 0.8125rem; color: var(--ink-soft); }
.numberline__legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.35rem; vertical-align: -1px; }
.numberline svg { width: 100%; height: auto; display: block; }

/* ---------- flash ---------- */
.flash {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--green-soft); color: var(--green); border: 1px solid #bfe6d1;
  border-radius: var(--radius); padding: 0.6rem 1rem; margin-bottom: 1.25rem; font-weight: 700;
}
.flash button { margin-left: auto; background: none; border: 0; color: inherit; font-size: 1.1rem; cursor: pointer; }
.flash--info { background: var(--blue-soft); color: var(--blue); border-color: #c5d3f5; }
.flash--warning { background: var(--amber-soft); color: var(--amber); border-color: #f0dcae; }
.flash--error { background: var(--red-soft); color: var(--red); border-color: #f3c2bc; }

/* ---------- distribution bars (students per maximum) ---------- */
.dist__row { display: grid; grid-template-columns: 4ch 1fr 2ch; align-items: center; gap: 0.75rem; margin: 0.4rem 0; font-variant-numeric: tabular-nums; }
.dist__label { font-weight: 800; text-align: right; white-space: nowrap; }
.dist__n { color: var(--ink-soft); text-align: right; }
.dist__bar { height: 14px; background: var(--grid); border-radius: 7px; overflow: hidden; }
.dist__bar i { display: block; height: 100%; background: var(--blue); border-radius: 7px; }

/* ---------- form errors and inline forms ---------- */
.field .error { color: var(--red); font-size: 0.8125rem; font-weight: 700; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--red); }
.errors { color: var(--red); font-weight: 700; margin: 0 0 1rem; padding-left: 1.25rem; }
form.inline { display: inline; }
.page-head__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.chart svg { width: 100%; height: auto; display: block; }

/* ---------- tooltips (one shared element, positioned by a small script) ---------- */
.tip {
  position: fixed; z-index: 50; max-width: 320px; pointer-events: none;
  background: var(--ink); color: #fff; font-size: 0.8125rem; font-weight: 700; line-height: 1.35;
  padding: 0.4rem 0.65rem; border-radius: 6px; box-shadow: 0 6px 20px rgba(21, 39, 74, 0.25);
}
.tip[hidden] { display: none; }
.hit { cursor: default; }
.hit--column { fill: transparent; }
.hit--column:hover { fill: var(--blue); fill-opacity: 0.08; }
circle.hit:hover { stroke: var(--ink); }

/* ---------- stats ---------- */
.stat { display: flex; flex-direction: column; gap: 0.15rem; }
.stat__label { color: var(--ink-soft); font-weight: 700; font-size: 0.875rem; }
.stat__value { font-size: 2.6rem; font-weight: 900; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat__value small { font-size: 1rem; font-weight: 700; color: var(--ink-soft); letter-spacing: 0; margin-left: 0.3rem; }
.stat__note { color: var(--ink-soft); font-size: 0.875rem; }
a.stat-link { color: inherit; display: block; }
a.stat-link:hover { text-decoration: none; }
a.stat-link:hover .panel { border-color: var(--blue); }

/* ---------- sheet editor (looks like the printed paper) ---------- */
.sheet {
  background: var(--card); border: 1px solid var(--rule); border-radius: 4px;
  padding: 2rem 2.5rem 2.25rem; max-width: 760px;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  box-shadow: 0 1px 0 var(--rule), 0 12px 32px rgba(21, 39, 74, 0.08);
}
.sheet__title { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--ink); padding-bottom: 0.5rem; margin-bottom: 1.25rem; }
.sheet__title h2 { font-size: 1.35rem; }
.sheet__title span { color: var(--ink-soft); font-weight: 700; }
.problems { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(10, auto); grid-auto-flow: column; column-gap: 3rem; row-gap: 0.25rem; }
.problems .problem:nth-child(5), .problems .problem:nth-child(15) { padding-bottom: 1rem; margin-bottom: 0.75rem; border-bottom: 1px dashed var(--rule); }
.problems--short { grid-template-rows: repeat(5, auto); }
.problems--short .problem:nth-child(5) { padding-bottom: 0; margin-bottom: 0; border-bottom: 0; }
.problem { display: flex; align-items: center; gap: 0.75rem; }
.problem label { width: 2.2ch; text-align: right; color: var(--ink-faint); font-weight: 700; font-variant-numeric: tabular-nums; }
.problem input {
  flex: 1; font: inherit; font-size: 1.25rem; font-weight: 700; letter-spacing: 0.06em;
  padding: 0.35rem 0.5rem; border: 0; border-bottom: 2px solid var(--rule); background: transparent; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.problem input:focus { outline: 0; border-bottom-color: var(--blue); background: rgba(255,255,255,0.7); }
.problem input[aria-invalid="true"] { border-bottom-color: var(--red); color: var(--red); }
.sheet__foot { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 1.5rem; }
.sheet__foot .help { margin: 0 0 0 auto; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.login__card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 2.25rem 2.25rem 2rem; }
.login__card .brand { justify-content: center; font-size: 1.6rem; margin-bottom: 0.25rem; }
.login__card .brand svg { width: 40px; height: 40px; }
.login__card p.lead { text-align: center; color: var(--ink-soft); margin-bottom: 1.75rem; }
.login__card .btn { width: 100%; justify-content: center; margin-top: 0.5rem; }

/* ---------- footer ---------- */
.footer { max-width: 1120px; margin: 0 auto; padding: 0 1.25rem 2rem; color: var(--ink-faint); font-size: 0.8125rem; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 3rem 1rem; }
.empty h2 { margin-bottom: 0.5rem; }
.empty p { color: var(--ink-soft); max-width: 46ch; margin: 0 auto 1.25rem; }

@media (max-width: 720px) {
  .search { display: none; }
  .topbar__inner { gap: 0.75rem; }
  .problems, .problems--short { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-flow: row; }
  .problems .problem:nth-child(15) { padding-bottom: 0; margin-bottom: 0; border-bottom: 0; }
  .problems .problem:nth-child(10) { padding-bottom: 1rem; margin-bottom: 0.75rem; border-bottom: 1px dashed var(--rule); }
  .topbar__inner { flex-wrap: wrap; padding-block: 0.6rem; }
  .nav { flex-wrap: wrap; }
  .topbar__right { margin-left: 0; }
  .sheet { padding: 1.25rem; }
  .level { --bar: 70px; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .nav a, .table .actions a { transition: background-color 120ms ease, color 120ms ease; }
}

code { font-family: var(--font); font-weight: 800; background: var(--blue-soft); color: var(--ink); padding: 0 0.3em; border-radius: 4px; }
