:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --accent: #1f6feb;
  --ok: #1a7f37;
  --bad: #b42318;
  --border: #d7dde3;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

header, main, footer { max-width: 860px; margin: 0 auto; padding: 0 1.25rem; }
header { padding-top: 2rem; }
h1 { margin: 0 0 .25rem; font-size: 1.7rem; }
.subtitle { color: var(--muted); margin-top: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin: 1.25rem 0;
}
.card h2 { margin-top: 0; font-size: 1.2rem; }

.format-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
/* Share row tracks across the two columns so the example tables line up,
   whatever the height of the bullet lists above them. */
.format-grid > div { display: grid; grid-template-rows: subgrid; grid-row: span 4; align-items: start; }
.format-grid h3 { margin: .25rem 0 .5rem; font-size: 1rem; }
.format-grid ul { padding-left: 1.1rem; margin: .25rem 0; }

pre {
  background: #0d1117;
  color: #e6edf3;
  padding: .65rem .8rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: .82rem;
}
code { background: #eef1f4; padding: .05rem .3rem; border-radius: 4px; font-size: .85em; }
pre code { background: none; padding: 0; }

/* Spreadsheet-style CSV examples (Excel-like): header row, gridlines, banding. */
.sheet-wrap { overflow-x: auto; margin: .25rem 0 .5rem; }
.sheet {
  border-collapse: collapse;
  font-family: "SF Mono", "Consolas", "Liberation Mono", Menlo, monospace;
  font-size: .8rem;
  background: #fff;
  border: 1px solid #c4ccd4;
}
.sheet th, .sheet td {
  border: 1px solid #d7dde3;
  padding: .3rem .55rem;
  text-align: left;
  white-space: nowrap;
}
.sheet thead th {
  background: #eef3f8;
  color: var(--ink);
  font-weight: 600;
  border-bottom: 2px solid #c4ccd4;
}
.sheet tbody tr:nth-child(even) td { background: #f7f9fb; }
.sheet td.blank { background: repeating-linear-gradient(45deg, #fafbfc, #fafbfc 4px, #f0f2f4 4px, #f0f2f4 8px); }
.sheet th.col-id { background: #e8f0fe; border-bottom-color: #7baaf7; }
.sheet th.col-cap { background: #fef3e2; border-bottom-color: #f9ab00; }
.sheet th.col-pref { background: #e6f4ea; border-bottom-color: #81c995; }
.col-role { display: block; font-weight: 400; font-size: .7rem; color: var(--muted); font-family: inherit; text-transform: uppercase; letter-spacing: .03em; }

.rules { color: var(--muted); font-size: .9rem; margin-top: 1rem; }
.rules strong { color: var(--ink); }

.tip-box { margin-top: 1.25rem; border: 1px solid #d7dde3; border-radius: 6px; }
.tip-box summary { padding: .6rem .9rem; cursor: pointer; font-size: .9rem; font-weight: 500; user-select: none; }
.tip-box summary:hover { background: #f7f9fb; border-radius: 6px; }
.tip-body { padding: .25rem .9rem .75rem; font-size: .9rem; }
.tip-body p { margin: .5rem 0; }
.tip-body ul { padding-left: 1.2rem; margin: .4rem 0; }
.tip-body li { margin-bottom: .3rem; }

.home-link { margin: 0 0 .5rem; font-size: .85rem; }
.home-link a { color: var(--accent); text-decoration: none; }
.home-link a:hover { text-decoration: underline; }

.uploads { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.uploads label { display: flex; flex-direction: column; gap: .4rem; font-weight: 600; font-size: .9rem; }
.uploads input { font-weight: 400; }

/* Column-mapping panels (step 2): collapsed summary when auto-detected. */
.mapping-block { margin-bottom: 1rem; }
.mapping-block details {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
}
.mapping-block summary {
  cursor: pointer;
  padding: .55rem .8rem;
  font-size: .9rem;
  font-weight: 600;
}
.mapping-block summary .status { font-weight: 400; color: var(--muted); }
.mapping-block summary .status.warn { color: var(--bad); font-weight: 600; }
.mapping-body {
  padding: .25rem .8rem .8rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.mapping-body .map-select {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  font-weight: 600;
}
.mapping-body select {
  padding: .3rem .45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 400;
}
.mapping-prefs { border: 0; padding: 0; margin: 0; }
.mapping-prefs legend { font-size: .9rem; font-weight: 600; padding: 0; }
.mapping-prefs .pref-list {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .9rem;
  margin-top: .35rem;
}
.mapping-prefs .pref-list label {
  font-size: .85rem;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-family: "SF Mono", "Consolas", "Liberation Mono", Menlo, monospace;
}
.mapping-hint { font-size: .8rem; color: var(--muted); margin: 0; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: .55rem 1.1rem;
  font-size: .95rem;
  cursor: pointer;
}
button:disabled { background: #aebfd4; cursor: not-allowed; }
.link-btn { background: none; color: var(--accent); padding: 0; text-decoration: underline; font-size: .85rem; }

.panel { margin-top: 1rem; padding: 1rem; border-radius: 8px; border: 1px solid var(--border); }
.panel.ok { border-color: #abdeb8; background: #ecf7ef; }
.panel.bad { border-color: #f1c4bd; background: #fcefed; }
.panel h3 { margin: 0 0 .5rem; }

.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.badge.ok { background: var(--ok); color: #fff; }
.badge.bad { background: var(--bad); color: #fff; }

.error-list { color: var(--bad); margin: .25rem 0 0; padding-left: 1.2rem; }
.muted { color: var(--muted); }
.warn { color: var(--bad); font-weight: 600; margin: 0 0 .5rem; }

table { border-collapse: collapse; width: 100%; margin-top: .75rem; font-size: .9rem; }
th, td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--border); }
th { background: #f0f3f6; }
td.unmatched { color: var(--bad); }

.summary { display: flex; flex-wrap: wrap; gap: 1.25rem; margin: .5rem 0 0; }
.summary div { font-size: .9rem; }
.summary strong { display: block; font-size: 1.3rem; }

.spinner { color: var(--muted); }

.login-form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  max-width: 320px;
  margin-bottom: 1rem;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-weight: 600;
  font-size: .9rem;
}
.login-form input {
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 400;
  color: var(--ink);
}
.login-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.login-error {
  color: var(--bad);
  margin: .5rem 0 0;
  font-size: .9rem;
}

#mode-bar {
  display: flex;
  gap: .5rem;
  margin: 1.25rem 0 0;
}
.mode-btn {
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .45rem 1.1rem;
  font-size: .9rem;
  cursor: pointer;
}
.mode-btn:hover { border-color: var(--accent); color: var(--accent); }
.mode-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.mode-desc { font-size: .85rem; margin: .4rem 0 0; }

.history-table td { vertical-align: middle; }
.history-actions { display: flex; gap: .75rem; white-space: nowrap; }

@media (max-width: 640px) {
  .format-grid, .uploads { grid-template-columns: 1fr; }
}

/* ---- Match type chooser ---- */
.match-type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: .75rem; }
.match-type-option {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  text-align: left;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  display: block;
}
.match-type-option:hover, .match-type-option:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, .15);
}
.match-type-option h3 { margin: 0 0 .4rem; font-size: 1.05rem; color: var(--accent); }
.match-type-option p { margin: 0 0 .5rem; font-size: .9rem; }
.match-type-option ul { margin: 0; padding-left: 1.1rem; font-size: .85rem; color: var(--muted); }
.match-type-option li { margin-bottom: .3rem; }
@media (max-width: 640px) { .match-type-grid { grid-template-columns: 1fr; } }

#match-type-bar { margin: 1.25rem 0 -0.5rem; }
#match-type-bar .link-btn { margin-left: .35rem; }

/* ---- Priority mode controls ---- */
#trainee-shape-row { margin-bottom: .9rem; }
.shape-question { margin: 0 0 .35rem; font-weight: 600; font-size: .92rem; }
.shape-option { display: block; font-size: .92rem; margin: .15rem 0; cursor: pointer; }
.shape-option input { margin-right: .4rem; }

#cohort-uploads { margin: .25rem 0 .75rem; }
.cohort-slot { display: flex; align-items: flex-start; gap: .75rem; flex-wrap: wrap; margin: .4rem 0; }
.cohort-slot > label { display: block; font-size: .92rem; }
.cohort-slot input[type="file"] { display: block; margin-top: .25rem; }
.cohort-slot .mapping-block { flex-basis: 100%; }
#add-cohort-btn { margin-top: .35rem; }

#cap-percent-row { margin: .75rem 0; }
#cap-percent-row label { font-size: .92rem; }
#cap-percent-row input { width: 4.5rem; margin-left: .4rem; }
#cap-percent-row .muted { margin: .25rem 0 0; font-size: .85rem; }

/* Phase breakdown chips in priority-mode results */
.phase-summary { display: flex; gap: .75rem; flex-wrap: wrap; margin: .5rem 0; }
.phase-summary div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .35rem .7rem;
  font-size: .88rem;
}

/* Mode tag in the history table */
.mode-tag {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 .5rem;
  font-size: .75rem;
  color: var(--muted);
  background: var(--bg);
}
