:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2433; --muted: #667085; --line: #d9dde5;
  --brand: #1f4e79; --brand-ink: #fff;
  --tested: #d4880f; --tested-bg: #fff6e0; --tested-line: #e8b04a;
  --danger: #b42318; --ok: #2e7d32;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 "Segoe UI", system-ui, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
#topbar { display: flex; align-items: center; gap: 28px; padding: 0 20px; height: 52px; background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 17px; }
.brand span { font-weight: 400; font-size: 12px; opacity: .75; margin-left: 8px; }
#nav a { color: #dce8f5; text-decoration: none; padding: 16px 12px; display: inline-block; }
#nav a.active, #nav a:hover { color: #fff; box-shadow: inset 0 -3px 0 #f2b84b; }
#app { padding: 18px 20px 40px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
.sub { color: var(--muted); margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
button, .btn { font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; color: var(--ink); text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: #f0f3f8; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: #17406a; }
button.danger { color: var(--danger); }
button.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { font-size: 14px; color: var(--ink); }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; position: sticky; top: 52px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f6f9fd; }
tr.tested-row td:first-child { box-shadow: inset 4px 0 0 var(--tested); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px 0 14px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }

/* ---- tested standards: always visually distinct ---- */
.pill-tested { display: inline-flex; align-items: center; gap: 3px; background: var(--tested); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px; letter-spacing: .03em; white-space: nowrap; }
.std { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid #aab4c3; border-radius: 6px; padding: 7px 9px; margin-bottom: 7px; cursor: grab; position: relative; }
.std:active { cursor: grabbing; }
.std .code { font-weight: 700; font-size: 12px; margin-right: 6px; }
.std .txt { font-size: 12.5px; color: #3a4252; margin-top: 2px; }
.std.tested { border-left-color: var(--tested); border-color: var(--tested-line); background: var(--tested-bg); box-shadow: 0 0 0 1px var(--tested-line) inset; }
.std.dragging { opacity: .4; }
.std .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.dim-untested .std:not(.tested) { opacity: .45; }
/* ---- standards placed in more than one unit ---- */
.placed-tag { color: #3a6ea5; }
.card-actions { display: flex; gap: 6px; align-items: center; margin-top: 5px; }
.card-actions select { flex: 1; min-width: 0; font-size: 11px; padding: 2px 4px; color: var(--muted); }
/* ---- archived standards: muted, clearly labelled ---- */
.pill-archived { display: inline-block; background: #667085; color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; letter-spacing: .03em; margin-left: 4px; white-space: nowrap; }
.std.archived { background: #f1f2f4; border-left-color: #98a2b3; border-style: dashed; }
.std.archived .txt, .std.archived .code { color: #667085; }
tr.archived-row td { color: #667085; background: #f7f7f8; }
.chip { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: #e9eef6; color: #33425b; margin: 0 4px 4px 0; }
.chip.x { cursor: pointer; }
.chip.x:hover { background: #f6d6d3; }

/* ---- builder ---- */
.builder { display: grid; grid-template-columns: 340px 1fr; gap: 14px; align-items: start; }
.bank { position: sticky; top: 64px; max-height: calc(100vh - 80px); display: flex; flex-direction: column; }
.bank .list { overflow: auto; margin-top: 8px; flex: 1; min-height: 120px; }
.bank.over, .unitlist.over { outline: 2px dashed var(--brand); outline-offset: -4px; }
.units { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; min-width: 0; }
/* each unit is a row: its header on the left, its standards to the right */
.unit { display: grid; grid-template-columns: 260px minmax(0, 1fr); background: #eaeef4; border-radius: 8px; border-left: 6px solid var(--c, #4f7cac); overflow: hidden; }
.unit.unit-dragging { opacity: .5; }
.unit .head { padding: 8px 10px; background: #fff; border-right: 1px solid var(--line); }
.unit .head input.title { width: 100%; font-weight: 600; border-color: transparent; padding: 2px 4px; }
.unit .head input.title:hover, .unit .head input.title:focus { border-color: var(--line); }
.unit .handle { cursor: grab; color: var(--muted); user-select: none; padding: 0 4px; }
.unit .weeks input[type=number] { width: 54px; padding: 2px 4px; }
.unit .stat { font-size: 12px; color: var(--muted); }
.unitlist { display: flex; flex-direction: row; gap: 8px; padding: 8px; min-height: 84px; overflow-x: auto; align-items: stretch; }
.unitlist .std { flex: 0 0 230px; width: 230px; margin-bottom: 0; }
.unitlist .empty { flex: 1; align-self: center; }
.empty { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 6px; }
.unit-add { align-self: flex-start; }

/* ---- pacing ---- */
.pace { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.pace-row { display: grid; grid-template-columns: 200px 1fr; align-items: center; min-width: 900px; border-bottom: 1px solid #eef0f4; }
.pace-label { font-weight: 600; padding: 6px 8px 6px 0; font-size: 13px; }
.pace-label small { display: block; font-weight: 400; color: var(--muted); }
.track { position: relative; height: 46px; background-image: linear-gradient(to right, #e6eaf0 1px, transparent 1px); background-size: calc(100% / var(--weeks)) 100%; }
.weeknums { display: grid; grid-template-columns: repeat(var(--weeks), 1fr); font-size: 10px; color: var(--muted); text-align: center; height: 20px; }
.bar { position: absolute; top: 7px; height: 32px; background: var(--c); color: #fff; border-radius: 6px; cursor: grab; display: flex; align-items: center; padding: 0 10px; font-size: 12px; font-weight: 600; overflow: hidden; white-space: nowrap; user-select: none; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.bar .rz { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; background: rgba(255,255,255,.28); }
.bar .rz.l { left: 0; } .bar .rz.r { right: 0; }
.testline { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dashed var(--danger); pointer-events: none; z-index: 2; }
.testline::after { content: "TEST"; position: absolute; top: -2px; left: 3px; font-size: 9px; color: var(--danger); font-weight: 700; }
.load { display: grid; grid-template-columns: repeat(var(--weeks), 1fr); align-items: end; height: 56px; gap: 1px; min-width: 700px; }
.load div { background: #8aa8c9; min-height: 1px; border-radius: 2px 2px 0 0; }
.warn { color: var(--danger); font-weight: 600; }
.ok { color: var(--ok); }

/* ---- alignment matrix ---- */
.matrix-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.matrix th, .matrix td { min-width: 120px; border-right: 1px solid #eef0f4; }
/* The matrix scrolls inside its own box, so its sticky header pins to the box top (not the page's 52px bar). */
.matrix th { top: 0; z-index: 2; }
.matrix th.rowh, .matrix td.rowh { position: sticky; left: 0; background: #fafbfc; min-width: 150px; z-index: 1; font-weight: 600; font-size: 12px; }
.matrix th.rowh { z-index: 3; }
.mchip { display: inline-block; padding: 2px 7px; margin: 0 4px 4px 0; border-radius: 5px; font-size: 12px; font-weight: 600; background: #e9eef6; border: 1px solid #c9d3e3; cursor: pointer; }
.mchip.tested { background: var(--tested-bg); border-color: var(--tested); color: #7a4b00; }
.mchip.tested::after { content: " ★"; color: var(--tested); }

/* ---- modal ---- */
#modal-root .backdrop { position: fixed; inset: 0; background: rgba(20,28,45,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 50; }
.modal { background: #fff; border-radius: 10px; width: 680px; max-width: 100%; padding: 18px 20px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 9px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); }
.legend { font-size: 12px; color: var(--muted); }

/* ---- print-preview sheet (Vocabulary and Overview / Print tabs) ---- */
.sheet { width: min(100%, 8.5in); margin: 0 auto 30px; padding: 0.55in 0.6in; background: #fff; border: 1px solid var(--line); box-shadow: 0 2px 10px rgba(20,28,45,.12); min-height: 11in; }
.sheet-title { border-bottom: 2px solid var(--ink); padding-bottom: 8px; margin-bottom: 14px; }
.sheet-name { font-size: 20px; font-weight: 700; }
.sheet .card { box-shadow: none; }
.sheet table { font-size: 13px; }

@media print {
  .sheet { width: auto; max-width: none; margin: 0; padding: 0; border: 0; box-shadow: none; min-height: 0; }
  #topbar, .tabs, .no-print, button { display: none !important; }
  body { background: #fff; }
  #app { padding: 0; }
  th { position: static; }
  .std, .unit { break-inside: avoid; }
}

/* ---- pacing timeline when a school calendar is loaded ---- */
.track.cal { background-image: none; }
.track .gl { position: absolute; top: 0; bottom: 0; width: 1px; background: #e6eaf0; }
.track .gl.pd { width: 2px; background: #9aa5b8; }
.weekhdr, .periodhdr { position: relative; height: 22px; }
.wkcell { position: absolute; top: 3px; font-size: 10px; color: var(--muted); text-align: center; border-left: 1px solid #e6eaf0; box-sizing: border-box; }
.pdcell { position: absolute; top: 0; height: 20px; line-height: 20px; font-size: 11px; font-weight: 600; text-align: center; overflow: hidden; white-space: nowrap; border-radius: 4px; box-sizing: border-box; border: 1px solid #c5d0e0; }
.pdcell.p0 { background: #e8eef7; } .pdcell.p1 { background: #f3f6fb; }
.loadx { position: relative; height: 56px; min-width: 700px; }
.loadx div { position: absolute; bottom: 0; background: #8aa8c9; border-radius: 2px 2px 0 0; border-right: 1px solid #fff; box-sizing: border-box; }

/* ---- school calendar page ---- */
.cal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 12px; }
.cal-month { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.cal-mh { background: #0a4e9a; color: #fff; font-weight: 700; text-align: center; padding: 5px; }
.cal-month table { table-layout: fixed; }
.cal-month th { position: static; text-align: center; padding: 3px 0; font-size: 11px; background: #f2f3f5; }
.cal-month td { text-align: center; padding: 0; height: 40px; border: 1px solid #eef0f4; vertical-align: top; position: relative; }
.cal-cell { cursor: pointer; background: #fff; }
.cal-cell:hover { outline: 2px solid var(--brand); outline-offset: -2px; z-index: 1; }
.cal-cell .cd { display: block; font-weight: 700; font-size: 13px; padding-top: 4px; }
.cal-cell small { display: block; font-size: 10px; color: #667085; }
.cal-pad { background: #b9d9ff; }
.cal-wknd { background: #eee; cursor: default; }
.cal-out .cd { color: #aab; font-weight: 400; }
.k-new_teacher { background: #f7a3a1 !important; } .k-pd { background: #c6b05a !important; } .k-teacher_workday { background: #93ce60 !important; }
.k-holiday { background: #ed424a !important; color: #000; } .k-makeup { background: #fdff1e !important; } .k-no_school { background: #d9dde5 !important; }
.k-graduation { background: #13a9dc !important; }
.k-used { background: #fff !important; box-shadow: inset 0 0 0 3px #fdff1e; }
.k-used small { color: var(--ok); font-weight: 700; }
.cal-edge { box-shadow: inset 0 0 0 2px #c0182a; border-radius: 50%; }
.pe { position: absolute; right: 2px; bottom: 0; font-size: 9px; color: var(--brand); font-style: normal; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; align-items: center; }
.cal-legend .sw { display: inline-block; width: 14px; height: 14px; border: 1px solid #99a; vertical-align: -3px; margin-right: 5px; }

/* start-of-year days that are outside the curriculum */
.track .bufband { position: absolute; left: 0; top: 0; bottom: 0; background: repeating-linear-gradient(135deg, #eef0f4, #eef0f4 4px, #fff 4px, #fff 8px); border-right: 2px solid #9aa5b8; z-index: 0; }

/* month bars under the school-week numbers: each runs from the month's first to last school day */
.monthhdr { position: relative; height: 26px; }
.mbar { position: absolute; top: 2px; height: 22px; line-height: 22px; font-size: 12px; font-weight: 600; color: #2f3747; text-align: center; overflow: hidden; white-space: nowrap; box-sizing: border-box; border-right: 2px solid #fff; border-radius: 3px; }
.mbar.m0 { background: #d3d8e0; } .mbar.m1 { background: #e3e6eb; }
.pace .pace-row { min-width: calc(200px + var(--trackmin, 700px)); }
.pace .pace-label { position: sticky; left: 0; background: var(--panel); z-index: 3; }

/* one small square per school day, tinted by the unit that covers it */
.dayhdr { position: relative; height: 24px; }
.dsq { position: absolute; top: 2px; height: 20px; box-sizing: border-box; border: 1px solid #fff; border-radius: 3px; background: color-mix(in srgb, var(--u, #e9ecf1) 38%, #fff); text-align: center; line-height: 18px; overflow: hidden; }
.dsq span { font-size: 9px; font-variant-numeric: tabular-nums; color: #2f3747; }
.dsq.buf { background: repeating-linear-gradient(135deg, #eef0f4, #eef0f4 3px, #fff 3px, #fff 6px); color: #667085; }
.dsq.pend { box-shadow: inset -2px 0 0 #0a4e9a; }
.dsq.test { outline: 2px solid #b42318; outline-offset: -2px; background: #fde7e5; }
