:root {
  --top-h: 0px; --stick-h: 0px;
  --bg: #f5f6f8; --panel: #fff; --text: #1f2933; --muted: #5f6b7a; --border: #d9dee5;
  --accent: #1d4ed8; --accent-dark: #1e3a8a; --danger: #b42318; --warn: #b54708; --ok: #067647;
  --radius: 6px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-size: 15px; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--accent); }
.top { background: #0f172a; color: #fff; }
.top .wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 16px; max-width: 1300px; margin: 0 auto; }
.top a { color: #dbe4ff; text-decoration: none; }
.top a:hover, .top a.on { color: #fff; text-decoration: underline; }
.top .brand { font-weight: 700; color: #fff; margin-right: 10px; }
.top .right { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.top form { margin: 0; }
.top button.link { background: none; border: 0; color: #dbe4ff; cursor: pointer; padding: 0; font: inherit; }
main { max-width: 1300px; margin: 0 auto; padding: 18px 16px 60px; }
h1 { font-size: 1.5rem; margin: 4px 0 14px; }
h2 { font-size: 1.15rem; margin: 22px 0 10px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #eef1f5; font-weight: 600; white-space: nowrap; }
th a { color: inherit; text-decoration: none; }
tr:hover td { background: #fafbfc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.messages { list-style: none; padding: 0; margin: 0 0 14px; }
.messages li { padding: 9px 12px; border-radius: var(--radius); margin-bottom: 6px; background: #eef4ff; border: 1px solid #c7d7fe; }
.messages li.error { background: #fef3f2; border-color: #fecdca; color: var(--danger); }
.messages li.success { background: #ecfdf3; border-color: #abefc6; color: var(--ok); }
label { display: block; font-weight: 600; margin-bottom: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input:not([type]), select, textarea {
  width: 100%; max-width: 560px; padding: 7px 9px; border: 1px solid #7b8494; border-radius: var(--radius); font: inherit; background: #fff;
}
textarea { max-width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
form div { margin-bottom: 12px; }
.helptext, form div > .helptext { display: block; color: var(--muted); font-size: .85rem; font-weight: normal; }
ul.errorlist { color: var(--danger); margin: 4px 0; padding-left: 18px; }
button, .btn { display: inline-block; background: var(--accent); color: #fff; border: 0; border-radius: var(--radius); padding: 8px 15px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
button:hover, .btn:hover { background: var(--accent-dark); }
.btn.secondary, button.secondary { background: #e4e8ee; color: var(--text); box-shadow: inset 0 0 0 1px #7b8494; }
.btn.danger, button.danger { background: var(--danger); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline { display: inline; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters div { margin: 0; }
.filters select, .filters input { width: auto; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: .78rem; font-weight: 600; background: #eef1f5; color: var(--muted); margin: 1px 2px 1px 0; white-space: nowrap; }
.badge.flag { background: #fff4e5; color: var(--warn); }
.badge.hold { background: #fef3f2; color: var(--danger); }
.badge.ok { background: #ecfdf3; color: var(--ok); }
.badge.stage { background: #eef4ff; color: var(--accent-dark); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--border); padding: 4px 0 10px 12px; }
.timeline li.note { border-color: #fdb022; }
.timeline li.email { border-color: #84adff; }
.timeline .when { color: var(--muted); font-size: .85rem; }
.preview-mail { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: #fff; }
.row-skip td { color: var(--muted); }
.row-new td:first-child { border-left: 3px solid var(--ok); }
.row-existing td:first-child { border-left: 3px solid #98a2b3; }
.row-skip td:first-child { border-left: 3px solid var(--danger); }
.auth { max-width: 420px; margin: 60px auto; }
.auth h1 { text-align: center; }
.devbar { background: #fffaeb; border-bottom: 1px solid #fedf89; color: #93370d; font-size: .85rem; text-align: center; padding: 4px; }
.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin: -4px 0 14px; border-bottom: 1px solid var(--border); }
.subnav a { padding: 6px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.subnav a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.qa-list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.qa { border-bottom: 1px solid var(--border); }
.qa:last-child { border-bottom: 0; }
.qa > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 24% 20% 1fr 70px; gap: 10px; align-items: center; padding: 9px 12px; }
.qa > summary::-webkit-details-marker { display: none; }
.qa > summary:hover { background: #f6f8fb; }
.qa > summary .qa-name { font-weight: 600; color: var(--accent); }
.qa > summary .qa-name::before { content: "\25B8  "; color: var(--muted); }
.qa[open] > summary .qa-name::before { content: "\25BE  "; }
.qa > summary .qa-score { text-align: right; font-weight: 600; }
.qa[open] > summary { background: #eef4ff; }
.qa-body { padding: 10px 12px 14px; background: #fafbfc; margin: 0; }
.qa-body textarea { max-width: 100%; }
.qa-dnp { margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--border); }
.qa-dnp > summary { cursor: pointer; color: var(--danger); }
.qa-dnp button { margin-top: 6px; }
@media (max-width: 800px) { .qa > summary { grid-template-columns: 1fr 1fr; } }
.navcount { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #fdb022; color: #1f2933; font-size: .75rem; font-weight: 700; text-align: center; }

/* ---- Sticky top bar, page toolbars and table headings ---- */
#topbar { position: sticky; top: 0; z-index: 100; }
.subnav { position: sticky; top: var(--top-h); z-index: 60; background: var(--bg); padding-top: 4px; }
.stick { position: sticky; top: var(--top-h); z-index: 50; }
.stick:not(.panel) { background: var(--bg); padding: 6px 0; }
.stick.panel { box-shadow: 0 2px 6px rgba(15, 23, 42, .08); }
thead th { position: sticky; top: calc(var(--top-h) + var(--stick-h)); z-index: 5; }
/* Sticky headings need the page itself to scroll, so tables only scroll sideways on narrow screens. */
@media (min-width: 900px) { .table-wrap { overflow: visible; } }
/* On phones keep the top bar to one line: the menu scrolls sideways instead of wrapping. */
@media (max-width: 700px) {
  .top .wrap { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; }
  .top .right { margin-left: 12px; }
}
table.stagegrid td input { width: 100%; max-width: none; font-size: .85rem; }
table.stagegrid td { vertical-align: top; }

/* Accessibility (WCAG 2.1 AA) */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 1000; background: #fff; color: var(--accent-dark); padding: 8px 14px; border-radius: var(--radius); font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.top :focus-visible { outline-color: #fff; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
.idle-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.idle-backdrop[hidden] { display: none; }
.idle-dialog { background: #fff; border-radius: var(--radius); padding: 20px; max-width: 440px; width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.idle-dialog button[hidden] { display: none; }

/* Logo, as on the dispatch calendar: on a small white panel in the dark top bar. */
.brand-logo { display: inline-block; background: #fff; border-radius: var(--radius); padding: 4px 10px; line-height: 0; margin-right: 6px; }
.brand-logo img { display: block; height: 46px; width: auto; }
.top a.brand-logo:hover { background: #fff; }
@media (max-width: 575.98px) { .brand-logo img { height: 36px; } }
.login-logo { display: block; width: 100%; max-width: 250px; height: auto; margin: .25rem auto 1.25rem; }

/* Staff top bar on wider screens: logo at the far left, the menu centered, name and Sign out at the far right. */
@media (min-width: 701px) {
  .staffnav .wrap { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; max-width: none; }
  .staffnav .navlinks { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 18px; }
  .staffnav .right { margin-left: 0; }
}
/* Phones keep the one-line, sideways-scrolling bar. */
@media (max-width: 700px) { .staffnav .navlinks { display: contents; } }

/* Top bar items as outlined buttons, matching the dispatch calendar's tabs: a white outline each,
   filled white for the page you're on and on hover. */
.staffnav .navlinks a, .staffnav .navbtn {
  display: inline-block; border: 1px solid rgba(255, 255, 255, .4); border-radius: 5px; padding: 5px 10px;
  color: #fff; background: none; text-decoration: none; font: inherit; line-height: 1.2; cursor: pointer;
  transition: background-color .12s ease-out, color .12s ease-out, border-color .12s ease-out;
}
.staffnav .navlinks a:hover, .staffnav .navlinks a.on, .staffnav .navbtn:hover {
  background: #fff; border-color: #fff; color: #0f172a; text-decoration: none;
}
@media (min-width: 701px) { .staffnav .navlinks { gap: 6px 8px; } }

/* Pages line up exactly when moving between them:
   - always leave room for the scrollbar, so short and long pages are the same width;
   - a heading that shares a row with a button sits where every other page's heading does;
   - the selected tab is bold, so each tab reserves its bold width and the others don't shift. */
html { overflow-y: scroll; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.pagehead h1 { margin-top: 0; }
.subnav a { display: inline-flex; flex-direction: column; align-items: center; }
.subnav a::after { content: attr(data-text); font-weight: 600; height: 0; visibility: hidden; overflow: hidden; pointer-events: none; }

/* A note the applicant should read before acting (e.g. what cancelling means). */
.panel.notice { border-left: 4px solid var(--warn); background: #fffaeb; }
