/* Centre name font: Anton (SIL Open Font License, see fonts/OFL.txt), served from this site. */
@font-face {
  font-family: 'Anton';
  src: url('fonts/Anton-Regular-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
:root {
  /* Colours from the centre logo: blue, navy, grey */
  --brand: #0f4c9e;
  --brand-dark: #0d3a73;
  --brand-grey: #4a4f55;
  --brand-soft: #e8eff9;
  --bg: #f3f5f7;
  --card: #ffffff;
  --line: #d5dbe1;
  --text: #1c2430;
  --muted: #5d6b7a;
  --red: #fdecec;
  --red-line: #c62828;
  --yellow: #fff7cc;
  --yellow-line: #d4a800;
  --grey: #eef1f4;
  --ok: #e7f5ea;
  --ok-line: #2e7d32;
  --header-h: 72px;
  --amber: #fff1d6;
  --amber-line: #c76b00;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.top {
  min-height: var(--header-h);
  flex-wrap: wrap;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 3px solid var(--brand);
  flex: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
#logo {
  height: 52px;
  width: auto;
}
#logo.missing {
  display: none;
}
/* Centre name on two lines, left aligned, as on the letterhead */
.brand-name {
  display: flex;
  flex-direction: column;
  font-family: 'Anton', 'Arial Narrow', Impact, sans-serif;
  font-weight: 400;
  font-size: 24px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  color: #111;
  white-space: nowrap;
}
.brand-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--brand-grey);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.save-state {
  font-size: 12px;
  color: var(--ok-line);
  max-width: 320px;
}
.save-state.warn {
  color: var(--red-line);
  font-weight: 600;
}
.controls select {
  margin-left: 6px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}
button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  padding: 5px 12px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
}
button.ghost {
  background: #fff;
  color: var(--brand);
}
.legend {
  margin-left: auto;
  padding: 4px 0;
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}
.sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
  border: 1px solid var(--line);
}
.sw.red {
  background: var(--red);
  border-color: var(--red-line);
}
.sw.yellow {
  background: var(--yellow);
  border-color: var(--yellow-line);
}
.sw.grey {
  background: var(--grey);
}
.strip {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--brand-soft);
  flex: none;
}
.privacy {
  margin: 0;
  padding: 4px 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- two panes, each scrolls on its own ---------- */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  /* --split is set by the drag handle (25% to 75%, remembered on this computer) */
  grid-template-columns: minmax(320px, calc(var(--split, 50%) - 7px)) 14px minmax(360px, 1fr);
  padding: 12px 16px 16px;
}
#splitter {
  cursor: col-resize;
  position: relative;
  touch-action: none;
  border-radius: 6px;
}
#splitter::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 6px;
  width: 2px;
  background: var(--line);
  border-radius: 2px;
}
#splitter:hover::before,
#splitter:focus-visible::before,
main.dragging #splitter::before {
  background: var(--brand);
  left: 5px;
  width: 4px;
}
#splitter:focus-visible {
  outline: none;
}
main.dragging {
  cursor: col-resize;
  user-select: none;
}
main.dragging iframe {
  pointer-events: none;
}
#form,
#side {
  min-height: 0;
  overflow: auto;
}
#side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
@media (max-width: 1000px) {
  body {
    display: block;
  }
  main {
    grid-template-columns: 1fr;
  }
  #splitter {
    display: none;
  }
  #side {
    height: 80vh;
  }
}

/* ---------- form ---------- */
fieldset {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0 0 12px;
  padding: 6px 14px 10px;
}
legend {
  font-weight: 700;
  color: var(--brand);
  padding: 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 8px;
  align-items: start;
  padding: 3px 0;
}
.field > label {
  padding-top: 6px;
  color: var(--muted);
}
.field input[type='text'],
.field select,
.field textarea {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
}
.field textarea {
  min-height: 52px;
  resize: vertical;
}
.fbox .ga {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.fbox .ga input[type='text'] {
  width: 52px;
  text-align: center;
}
.fbox .ga input.ga-d {
  width: 40px;
}
.fbox .ga .unit {
  color: var(--muted);
  font-size: 12px;
}
.fbox.is-red input,
.fbox.is-red select,
.fbox.is-red textarea {
  background: var(--red);
  border-color: var(--red-line);
}
.fbox.is-yellow input,
.fbox.is-yellow select,
.fbox.is-yellow textarea {
  background: var(--yellow);
  border-color: var(--yellow-line);
}
.fbox .msg {
  color: var(--red-line);
  font-size: 12px;
}
.fbox .msg:empty {
  display: none;
}
.fbox .hint {
  color: var(--muted);
  font-size: 12px;
}
.computed {
  background: var(--grey);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
}
.computed .working {
  color: var(--muted);
  font-size: 12px;
}
.reset {
  font-size: 12px;
  margin-top: 4px;
  padding: 2px 8px;
  background: #fff;
  color: var(--brand);
}

/* ---------- status bar ---------- */
#status .bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
}
#status .bar.blocked {
  background: var(--red);
  border: 1px solid var(--red-line);
}
#status .bar.ready {
  background: var(--ok);
  border: 1px solid var(--ok-line);
}
#status .bar .grow {
  flex: 1;
}
#status .bar button {
  padding: 2px 10px;
  font-size: 12px;
  background: #fff;
  color: var(--red-line);
  border-color: var(--red-line);
}
#status ul {
  margin: 6px 0 0;
  padding: 6px 12px 6px 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 140px;
  overflow: auto;
  font-size: 12px;
}
#status li {
  cursor: pointer;
}
#status li:hover {
  text-decoration: underline;
}

/* ---------- report preview ---------- */
#preview {
  flex: 1;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
#preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
#preview .draft {
  height: 100%;
  overflow: auto;
  padding: 16px;
  font-family: 'Trebuchet MS', sans-serif;
  font-size: 12pt;
}
#preview .draft table {
  border-collapse: collapse;
  width: 100%;
}
#preview .draft td {
  padding: 2px 4px;
  vertical-align: top;
}
#preview .draft table.grid td,
#preview .draft table.head td,
#preview .draft table.box > tbody > tr > td {
  border: 1px solid #000;
}
#preview .draft td.h,
#preview .draft td.ht,
#preview .draft table.head td {
  background: #d9d9d9;
}
#preview .draft p {
  margin: 0;
}

/* ---------- worked out by code (grey) ---------- */
.fbox.is-grey input[type='text'] {
  background: var(--grey);
}
.fbox.is-grey input::placeholder {
  color: var(--text);
  opacity: 0.75;
}
.calc-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.calc-note:empty {
  display: none;
}
.calc-note .use {
  color: var(--brand-grey);
}
.calc-note .working {
  font-size: 11px;
}

/* ---------- quick-pick buttons for short choice lists ---------- */
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid transparent;
}
.pill {
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
}
.pill:hover {
  border-color: var(--brand);
}
.pill:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.pill[aria-pressed='true'] {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.fbox.is-yellow .pill[aria-pressed='true'] {
  background: var(--yellow);
  border-color: var(--yellow-line);
  color: var(--text);
}
.fbox.is-red .pills {
  background: var(--red);
  border-color: var(--red-line);
}

/* ---------- fields on one line (biometry and similar) ---------- */
.group-row > .glabel {
  padding-top: 20px;
  color: var(--muted);
  font-weight: 600;
}
.cells {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: flex-start;
}
.cell {
  display: flex;
  flex-direction: column;
  flex: 1 1 80px;
  min-width: 80px;
  max-width: 180px;
}
.cell.cell-ga {
  flex: 0 0 auto;
  max-width: none;
}
.cell.cell-choice {
  max-width: none;
}
.cell .clabel {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
  white-space: nowrap;
}
.cell[hidden],
.group-row[hidden] {
  display: none;
}

/* ---------- dates check cards (report side, top) ---------- */
#checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
}
#checks[hidden] {
  display: none;
}
.check-card {
  border-radius: 10px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  background: var(--card);
}
.check-card .check-head {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.check-card .check-work {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.check-card.warn {
  background: var(--amber);
  border-color: var(--amber-line);
}
.check-card.warn .check-head {
  color: #8a3b00;
}
.check-card.good {
  background: var(--ok);
  border-color: var(--ok-line);
}
.check-card.good .check-head {
  color: var(--ok-line);
}
.check-card.info {
  background: var(--brand-soft);
  border-color: var(--brand);
}
.check-card.info .check-head {
  font-size: 15px;
  color: var(--brand-dark);
}

/* ---------- save and saved reports windows ---------- */
.dlg {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  width: min(520px, 94vw);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.dlg.wide {
  width: min(980px, 96vw);
  max-height: 86vh;
}
.dlg::backdrop {
  background: rgba(13, 58, 115, 0.35);
}
.dlg h2 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--brand-dark);
}
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dlg-sub {
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 12px;
}
.dlg input[type='text'] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}
.autoname {
  font-weight: 600;
  background: var(--brand-soft);
  border-radius: 6px;
  padding: 6px 8px;
}
.dlg-msg {
  color: var(--red-line);
  font-size: 13px;
  margin-top: 8px;
}
.dlg-msg:empty {
  display: none;
}
.dlg-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.saved-list h3 {
  margin: 14px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand);
  border-bottom: 1px solid var(--line);
  padding-bottom: 3px;
}
.saved-row {
  display: grid;
  grid-template-columns: 60px 1fr auto auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--grey);
}
.saved-row.is-current {
  background: var(--brand-soft);
}
.saved-row .fmt {
  font-weight: 700;
  color: var(--brand-dark);
}
.saved-row .note {
  font-size: 12px;
  color: var(--muted);
}
.saved-row .time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.saved-row button {
  padding: 3px 10px;
  font-size: 12px;
}
.badge {
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.badge.ok {
  background: var(--ok);
  color: var(--ok-line);
  border: 1px solid var(--ok-line);
}
.badge.todo {
  background: var(--red);
  color: var(--red-line);
  border: 1px solid var(--red-line);
}
button.danger {
  color: var(--red-line);
  border-color: var(--red-line);
}
.saved-list .empty {
  color: var(--muted);
}

/* ---------- dictation box and AI-filled boxes (Phase 2) ---------- */
fieldset.dictation textarea {
  width: 100%;
  min-height: 90px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}
.ai-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.ai-msg {
  font-size: 12px;
  color: var(--muted);
}
.field.is-ai input,
.field.is-ai select,
.field.is-ai textarea {
  background: var(--yellow);
  border-color: var(--yellow-line);
}
.field.is-ai > label::after {
  content: 'AI';
  margin-left: 6px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  color: #7a5b00;
  background: var(--yellow);
  border: 1px solid var(--yellow-line);
  border-radius: 3px;
}

/* ---------- Admin link in the header (shown only to admins, src/ui/admin-link.js) ---------- */
.admin-link {
  font-size: 12px;
  color: var(--brand);
  text-decoration: underline;
}
.admin-link[hidden] {
  display: none;
}
