/* --------------------------------------------------------------------------
   Residency evaluation system
   One stylesheet, no build step, no external fonts or CDNs.
   -------------------------------------------------------------------------- */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e2e5ea;
  --border-strong: #cbd2da;
  --text: #16202c;
  --text-muted: #5d6b7a;
  --text-faint: #8a96a3;
  --accent: #1d4ed8;
  --accent-dark: #1739a8;
  --accent-soft: #eef2ff;
  --ok: #0f7b47;
  --ok-soft: #e5f4ec;
  --warn: #9a6100;
  --warn-soft: #fdf3e0;
  --danger: #b02a37;
  --danger-soft: #fdecee;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(16, 26, 40, .06), 0 1px 3px rgba(16, 26, 40, .04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2029;
    --surface-2: #20272f;
    --border: #2c3540;
    --border-strong: #3c4855;
    --text: #e6ebf1;
    --text-muted: #a3b0bd;
    --text-faint: #7d8a97;
    --accent: #6f9dff;
    --accent-dark: #8fb4ff;
    --accent-soft: #1c2942;
    --ok: #4ecb8c;
    --ok-soft: #16301f;
    --warn: #e5aa4a;
    --warn-soft: #332713;
    --danger: #ff8a94;
    --danger-soft: #3a1c20;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

h1, h2, h3, h4 { line-height: 1.25; margin: 0; font-weight: 640; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

/* --- layout --------------------------------------------------------------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 56px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 680;
  color: var(--text);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; letter-spacing: -.02em;
}
.nav { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.nav a {
  padding: 6px 11px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .who {
  color: var(--text-faint);
  font-size: 13px;
  padding-left: 12px;
  margin-left: 6px;
  border-left: 1px solid var(--border);
}

/* Second-level navigation: the pages inside the current section. */
.subbar { border-top: 1px solid var(--border); background: var(--surface-2); }
.subbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 20px;
  display: flex; gap: 2px; flex-wrap: wrap;
}
.subbar a {
  padding: 9px 12px; font-size: 13.5px; font-weight: 500;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subbar a:hover { color: var(--text); text-decoration: none; }
.subbar a.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: 26px 20px 72px; }
main.narrow { max-width: 760px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 18px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head .sub { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.card-head .hint { color: var(--text-muted); font-size: 13px; font-weight: 400; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* --- tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 650; background: var(--surface-2);
  white-space: nowrap; position: sticky; top: 0;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.shrink { width: 1%; white-space: nowrap; }

/* --- buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  font: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-link {
  border: none; background: none; color: var(--accent); padding: 0;
  font: inherit; cursor: pointer; text-decoration: none;
}
.btn-link:hover { text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --- forms ---------------------------------------------------------------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 14px;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.field { margin-bottom: 14px; }
.field .help { font-size: 12.5px; color: var(--text-faint); margin-top: 4px; font-weight: 400; }
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; color: var(--text); font-size: 14px; margin-bottom: 8px; }
.check input { margin: 3px 0 0; flex: none; }
.check span.help { display: block; font-size: 12.5px; color: var(--text-faint); font-weight: 400; }

fieldset { border: none; margin: 0; padding: 0; }

/* --- badges & chips ------------------------------------------------------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.pill {
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); font-size: 13.5px; font-weight: 550;
}
.pill:hover { text-decoration: none; border-color: var(--border-strong); color: var(--text); }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- stats ---------------------------------------------------------------- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .n { font-size: 27px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.stat.alert .n { color: var(--danger); }

/* --- score display -------------------------------------------------------- */
.score { font-variant-numeric: tabular-nums; font-weight: 650; }
.score-lg { font-size: 26px; letter-spacing: -.02em; }
.score-na { color: var(--text-faint); font-weight: 400; }

.meter {
  height: 6px; border-radius: 3px; background: var(--border);
  overflow: hidden; min-width: 70px; margin-top: 5px;
}
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.good > i { background: var(--ok); }
.meter.mid > i { background: var(--warn); }
.meter.low > i { background: var(--danger); }

/* --- evaluation form ------------------------------------------------------ */
.form-shell { max-width: 820px; margin: 0 auto; }
.form-banner {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.form-banner h1 { margin-bottom: 6px; }
.form-banner .about { font-size: 15px; color: var(--text); margin-top: 10px; }
.form-banner .about strong { font-weight: 640; }
.form-banner .note {
  margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}

.qsection { margin-bottom: 18px; }
.qsection > h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); margin: 0 0 8px 2px;
}

.question {
  background: var(--surface); border: 1px solid var(--border);
  padding: 15px 18px; border-bottom: none;
}
.question:first-of-type { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.question:last-of-type { border-radius: 0 0 var(--radius-lg) var(--radius-lg); border-bottom: 1px solid var(--border); }
.question.only { border-radius: var(--radius-lg); border-bottom: 1px solid var(--border); }
.question.invalid { border-left: 3px solid var(--danger); background: var(--danger-soft); }
.question .prompt { font-weight: 520; margin-bottom: 4px; }
.question .req { color: var(--danger); margin-left: 3px; }
.question .qhelp { font-size: 12.5px; color: var(--text-faint); margin-bottom: 10px; }
.question .error { font-size: 12.5px; color: var(--danger); font-weight: 600; margin-top: 8px; }

/* Rating row: five radio options, plus an optional "not observed". */
.scale { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.scale label {
  flex: 1 1 110px; margin: 0; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 9px; text-align: center;
  background: var(--surface); color: var(--text-muted);
  font-weight: 500; font-size: 12.5px;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
  transition: background .1s, border-color .1s;
}
.scale label:hover { border-color: var(--accent); }
.scale label .v { font-size: 16px; font-weight: 680; color: var(--text); font-variant-numeric: tabular-nums; }
.scale label .t { line-height: 1.3; }
.scale input { position: absolute; opacity: 0; pointer-events: none; }
.scale input:checked + .v,
.scale label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.scale label:has(input:checked) .v { color: var(--accent); }
.scale label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.scale label.na { flex: 0 0 auto; min-width: 96px; color: var(--text-faint); }

.form-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-top: 20px; flex-wrap: wrap;
}
.save-state { font-size: 13px; color: var(--text-faint); }

/* --- misc ----------------------------------------------------------------- */
.flash {
  max-width: 1180px; margin: 16px auto -6px; padding: 11px 16px;
  border-radius: var(--radius); font-size: 14px; font-weight: 500;
  border: 1px solid transparent;
}
.flash-success { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

.empty { padding: 34px 20px; text-align: center; color: var(--text-faint); font-size: 14px; }
.empty strong { display: block; color: var(--text-muted); font-size: 15px; margin-bottom: 5px; font-weight: 600; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mb0 { margin-bottom: 0; }
.right { text-align: right; }

.notice {
  background: var(--accent-soft); color: var(--accent);
  border-radius: var(--radius); padding: 11px 14px; font-size: 13.5px; margin-bottom: 16px;
}
.notice-warn { background: var(--warn-soft); color: var(--warn); }

details.inline-edit > summary {
  cursor: pointer; color: var(--accent); font-size: 13px; list-style: none;
}
details.inline-edit > summary::-webkit-details-marker { display: none; }
details.inline-edit > summary:hover { text-decoration: underline; }
details.inline-edit[open] > summary { margin-bottom: 12px; }
details.inline-edit > div {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}

.picker {
  max-height: 290px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
}
.picker label {
  display: flex; align-items: baseline; gap: 9px; margin: 0;
  padding: 8px 13px; border-bottom: 1px solid var(--border);
  font-weight: 500; color: var(--text); font-size: 14px; cursor: pointer;
}
.picker label:last-child { border-bottom: none; }
.picker label:hover { background: var(--surface); }
.picker input { flex: none; }
.picker .detail { color: var(--text-faint); font-size: 12.5px; margin-left: auto; text-align: right; }

.auth-shell { max-width: 400px; margin: 9vh auto; padding: 0 20px; }
.auth-shell .card-body { padding: 26px; }
.auth-shell h1 { margin-bottom: 5px; }
.auth-shell .sub { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }

.comment {
  border-left: 2px solid var(--border-strong);
  padding: 2px 0 2px 13px; margin-bottom: 13px;
  font-size: 14px; white-space: pre-wrap;
}
.comment .who { display: block; font-size: 12px; color: var(--text-faint); margin-top: 4px; font-weight: 500; }

.print-only { display: none; }
.print-id { display: none; }

.wordcount { font-size: 12px; color: var(--text-faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.wordcount.over { color: var(--danger); font-weight: 650; }

/* ---------------------------------------------------------------------------
   Printable record sheets
   ---------------------------------------------------------------------------
   A weekly log or a signed checklist is a document the programme files, so it
   gets its own layout rather than the application's. On screen it reads as a
   plain sheet; printed, it is the record. */

.print-bar {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.print-bar-inner {
  max-width: 900px; margin: 0 auto; padding: 0 24px;
  display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  font-size: 13px;
}

.sheet { max-width: 900px; margin: 0 auto; padding: 30px 24px 60px; }

.sheet-head {
  display: flex; gap: 24px; align-items: flex-start; justify-content: space-between;
  border-bottom: 2px solid var(--text); padding-bottom: 14px; margin-bottom: 22px;
}
.sheet-program {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 6px;
}
.sheet-head h1 { font-size: 24px; margin: 0; }
.sheet-sub { color: var(--text); margin-top: 6px; font-size: 17px; font-weight: 600; }
.sheet-meta { text-align: right; font-size: 12px; color: var(--text-faint); white-space: nowrap; }

/* A labelled block of facts at the top of a record. */
.sheet-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px 22px; margin-bottom: 24px;
}
.sheet-facts dt {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 2px;
}
.sheet-facts dd { margin: 0; font-size: 14px; }

.sheet-section { margin-bottom: 26px; break-inside: avoid; }
.sheet-section > h2 {
  font-size: 15px; margin: 0 0 8px;
  border-bottom: 1px solid var(--border); padding-bottom: 5px;
}
.sheet-section .hint { font-weight: 400; color: var(--text-faint); font-size: 12px; }

.sheet table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); border-bottom: 1px solid var(--border); padding: 5px 8px 5px 0;
}
.sheet table td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border-soft, #eef1f3); vertical-align: top; }
.sheet table tfoot td { border-top: 1.5px solid var(--text); border-bottom: none; font-weight: 650; }

.sheet-signature {
  border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px;
  font-size: 12.5px; margin-top: 10px;
}

.sheet-foot {
  margin-top: 34px; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-faint);
}
.sheet-confidential { margin-top: 4px; font-style: italic; }

/* The line at the foot of every page that points to the guide. */
.site-foot {
  max-width: 1120px; margin: 24px auto 0; padding: 14px 20px 28px;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
  display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline;
}
.site-foot a { color: var(--text-muted); font-weight: 600; }
.site-foot a:hover { color: var(--text); }

@media print {
  .topbar, .subbar, .page-actions, .btn, .flash, .print-bar, .site-foot { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
  .print-only { display: block; }

  /* Margins only. Fixing the paper to portrait letter made a printout come out
     sideways whenever the print dialog had been left on Landscape: the browser
     kept the portrait layout and turned it onto the landscape sheet. With no
     size given the page simply flows into whichever orientation is chosen. */
  @page { margin: 15mm 14mm 14mm; }

  /* Who printed this, and when, at the top of any printed page. */
  .print-id {
    display: block; margin: 0 0 14px; padding-bottom: 6px;
    border-bottom: 1px solid #999; font-size: 10pt; color: #333;
  }
  .print-id strong { color: #000; }

  /* A form printed straight from the browser should read as a record, not as
     a screenshot of inputs: no boxes, no controls. */
  body:not(.printable) input,
  body:not(.printable) textarea,
  body:not(.printable) select {
    border: none !important; box-shadow: none !important; background: transparent !important;
    padding-left: 0 !important; appearance: none; -webkit-appearance: none;
  }
  body:not(.printable) ::placeholder { color: transparent !important; }
  body:not(.printable) .card { border-color: #bbb; }
  body:not(.printable) .grid { display: block; }
  body:not(.printable) .card, body:not(.printable) tr { break-inside: avoid; }

  /* Print in black on white regardless of the viewer's theme. */
  body.printable, body.printable .sheet { background: #fff; color: #000; }
  body.printable .sheet { max-width: none; margin: 0; padding: 0; }
  body.printable .sheet-program,
  body.printable .sheet-meta,
  body.printable .sheet-foot,
  body.printable .sheet table th { color: #444; }
  body.printable .sheet-sub,
  body.printable .sheet-facts dd { color: #000; }
  body.printable .sheet-facts dt { color: #444; }

  .sheet table { font-size: 11pt; }
  .sheet table thead { display: table-header-group; }
  .sheet table tr, .sheet-signature, .sheet-facts { break-inside: avoid; }
  .sheet-section > h2 { break-after: avoid; }
  .sheet-foot { position: static; }

  a { color: inherit; text-decoration: none; }
}

@media (max-width: 640px) {
  .topbar-inner { min-height: 0; padding: 10px 16px; }
  .nav { margin-left: 0; width: 100%; }
  main { padding: 18px 14px 60px; }
  .scale label { flex: 1 1 100%; flex-direction: row; justify-content: flex-start; gap: 9px; text-align: left; }
}

/* Two-step sign-in (account-2fa.ejs). The site's security policy does not allow style="" attributes. */
.qr { width: 220px; max-width: 100%; margin: 16px 0; padding: 8px; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.qr svg { display: block; width: 100%; height: auto; }
.recovery-codes { font-size: 1.15rem; line-height: 1.9; letter-spacing: .04em; margin: 16px 0; padding: 14px 18px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; user-select: all; }
.manual-key { font-size: 1.05rem; letter-spacing: .05em; }
.code-input { max-width: 200px; font-size: 1.25rem; letter-spacing: .12em; }
.btn-block { width: 100%; justify-content: center; }
