:root {
  --navy: #1f3a5f;
  --navy-dark: #16283f;
  --accent: #2e7d32;
  --danger: #b3261e;
  --warn: #b06d00;
  --border: #d7dce2;
  --bg: #f5f7f9;
  --text: #1b2430;
  --muted: #5b6675;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
.topnav { background: var(--navy); padding: 12px 24px; display: flex; gap: 20px; align-items: center; }
.topnav a { color: #fff; text-decoration: none; font-size: 14px; }
.topnav a.brand { font-weight: 700; font-size: 17px; margin-right: 12px; }
.topnav a:hover { text-decoration: underline; }
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin-top: 0; }
h2 { font-size: 17px; color: var(--navy-dark); }
table { width: 100%; border-collapse: collapse; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #eef1f4; font-weight: 600; }
tr:hover td { background: #fafcff; }
a.btn, button.btn { display: inline-block; background: var(--navy); color: #fff; padding: 7px 14px; border-radius: 4px; text-decoration: none; font-size: 13px; border: none; cursor: pointer; }
a.btn.secondary, button.btn.secondary { background: #6b7684; }
a.btn.danger, button.btn.danger { background: var(--danger); }
.card { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 16px 20px; margin-bottom: 18px; }
form.stacked label { display: block; margin: 10px 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
form.stacked input, form.stacked select, form.stacked textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.row-actions { display: flex; gap: 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.pending, .badge.in_progress { background: #fff3cd; color: var(--warn); }
.badge.approved { background: #e3f4e3; color: var(--accent); }
.badge.denied, .badge.withdrawn { background: #fbe4e2; color: var(--danger); }
.badge.pending_info, .badge.referred_out, .badge.open { background: #e3ecf9; color: var(--navy); }
.badge.closed { background: #e6e6e6; color: #555; }
.muted { color: var(--muted); font-size: 13px; }
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; }
.followup-overdue { color: var(--danger); font-weight: 700; }
.section-title-row { display: flex; justify-content: space-between; align-items: center; margin-top: 26px; }

/* --- alerts --- */
.alert { padding: 10px 14px; border-radius: 5px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.alert.success { background: #e8f5e9; border-color: #b6ddb8; color: #1e5c22; }
.alert.danger  { background: #fdecea; border-color: #f2c3bf; color: #8c1d18; }
.alert.warn    { background: #fff8e1; border-color: #f0dca0; color: #7a4f00; }

/* --- visit tabs --- */
.visit-header { margin-bottom: 12px; }
.visit-header h1 a { color: var(--text); text-decoration: none; }
.visit-header h1 a:hover { text-decoration: underline; }
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 16px; text-decoration: none; color: var(--muted); font-size: 14px;
  border: 1px solid transparent; border-bottom: none; border-radius: 5px 5px 0 0; margin-bottom: -2px;
}
.tabs a:hover { color: var(--navy); background: #eef1f4; }
.tabs a.active { background: #fff; border-color: var(--border); border-bottom: 2px solid #fff; color: var(--navy); font-weight: 600; }

/* --- match scores --- */
.score { display: inline-block; padding: 3px 9px; border-radius: 4px; font-weight: 700; font-size: 13px; }
.score.high { background: #e3f4e3; color: var(--accent); }
.score.mid  { background: #fff3cd; color: var(--warn); }
.score.low  { background: #f0f0f0; color: #666; }

/* --- screening sheet layout --- */
.sheet-layout { display: grid; grid-template-columns: minmax(0,1fr) 380px; gap: 22px; align-items: start; }
@media (max-width: 1000px) { .sheet-layout { grid-template-columns: 1fr; } }
.sheet-layout aside { position: sticky; top: 16px; }
.card h2 { margin-top: 0; font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
details.card > summary { cursor: pointer; list-style: revert; }
details.card > summary h2 { margin: 0; }

.determination { max-height: calc(100vh - 40px); overflow-y: auto; }
.determination-item { border-top: 1px solid var(--border); padding: 12px 0; }
.determination-item:first-of-type { border-top: none; }
.reasons { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.reasons.blockers { color: var(--danger); }
.next-steps summary { cursor: pointer; font-size: 12.5px; color: var(--navy); margin-top: 6px; }
.disclaimer { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; font-style: italic; }
.program-picker { max-height: 190px; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px; padding: 8px; margin-bottom: 10px; }
label.check { display: block; font-weight: 400; font-size: 13px; margin: 3px 0; color: var(--text); }
label.check input { width: auto; margin-right: 6px; }

/* --- stat row --- */
.stat-row { display: flex; gap: 28px; flex-wrap: wrap; }
.stat-row > div { display: flex; flex-direction: column; }
.stat-row span { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-row strong { font-size: 19px; margin-top: 2px; }

/* --- stat grid (KPI cards: label, big number, optional subtitle) --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card.stat { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0; }
.card.stat > span.muted:first-child { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card.stat > strong { font-size: 26px; color: var(--navy-dark); }
.card.stat > span.muted:last-child { font-size: 12px; }

/* Row-level forms sit inline inside table cells. */
td form { display: inline; }
.hidden { display: none; }

/* --- two-column page layout (visit detail: actions left, history/notes right) --- */
.two-col { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(0,1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* --- workflow pipeline with directional arrows --- */
.pipeline.compact { display: flex; gap: 2px; flex-wrap: wrap; align-items: center; max-width: 620px; }
.pipeline-stage.compact { padding: 6px 10px; border-radius: 4px; background: #eef1f4; color: var(--muted); font-size: 11.5px; border: 1px solid transparent; white-space: nowrap; }
.pipeline-stage.compact.current { background: var(--navy); color: #fff; font-weight: 600; }
.pipeline-stage.compact.terminal { border-style: dashed; }
.pipeline-arrow { color: var(--border); font-size: 14px; padding: 0 1px; }

/* --- printable letters --- */
.letter-page { background: #fff; max-width: 800px; margin: 0 auto 24px; padding: 48px 56px; border: 1px solid var(--border); font-size: 14px; line-height: 1.55; }
.letter-office { font-weight: 700; text-align: center; margin-bottom: 22px; padding-bottom: 12px; border-bottom: 2px solid var(--navy); }
.letter-office .name { font-size: 16px; color: var(--navy); }
.letter-not-collection { font-weight: 700; text-transform: uppercase; margin: 14px 0; }
.letter-lang-divider { border: none; border-top: 1px dashed var(--border); margin: 24px 0; }
.letter-fields div { margin: 3px 0; }
.letter-blank { display: inline-block; min-width: 160px; border-bottom: 1px solid #000; }
@media print {
  .no-print { display: none !important; }
  .letter-page { border: none; margin: 0; padding: 0; }
  body { background: #fff; }
}
