:root {
  --ink: #17181c;
  --muted: #6b7280;
  --line: #e3e5e9;
  --bg: #f6f7f9;
  --card: #ffffff;
  --blue: #1d4ed8;
  --blue-soft: #eef2ff;
  --green: #0f7b3f;
  --green-soft: #e8f5ec;
  --amber: #92610a;
  --amber-soft: #fdf4e0;
  --red: #b42318;
  --red-soft: #fdeceb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.6 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header.top {
  background: var(--ink);
  color: #fff;
  padding: 0.9rem 1.5rem;
}
header.top a { color: #fff; text-decoration: none; font-weight: 600; font-size: 1.05rem; }
header.top .sub { color: #b9bec9; font-size: 0.85rem; font-weight: 400; margin-left: 0.6rem; }

main { max-width: 1040px; margin: 0 auto; padding: 1.5rem; }

.step {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem 1.5rem 1.5rem;
  margin-bottom: 1.5rem;
}
.step h2 { margin: 0 0 .2rem; font-size: 1.15rem; }
.step .lede { color: var(--muted); margin: 0 0 1.1rem; font-size: 0.95rem; }
.stepnum {
  display: inline-grid; place-items: center;
  width: 1.7rem; height: 1.7rem; border-radius: 50%;
  background: var(--blue); color: #fff; font-size: 0.9rem; font-weight: 700;
  margin-right: .55rem; vertical-align: -0.35rem;
}

h3 { font-size: 0.95rem; margin: 1.2rem 0 .4rem; }

/* upload row */
.uploader { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .85rem; font-weight: 600; }
input[type=file], select, input[type=text], input[type=number], textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink);
}
input[type=number] { width: 5.5rem; }
textarea { width: 100%; min-height: 4rem; }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  background: var(--blue); color: #fff;
}
button.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
button.danger { background: #fff; color: var(--red); border-color: #f0c9c5; }
button.go { background: var(--green); }
button:disabled { opacity: .45; cursor: not-allowed; }

/* job lists */
ul.jobs { list-style: none; margin: 0; padding: 0; }
ul.jobs li {
  display: flex; align-items: center; gap: .85rem;
  padding: .7rem .1rem; border-bottom: 1px solid var(--line);
}
ul.jobs li:last-child { border-bottom: 0; }
.jobmain { flex: 1; min-width: 0; }
.jobtitle { font-weight: 600; }
.jobsub { color: var(--muted); font-size: .85rem; }

.pill {
  font-size: .78rem; font-weight: 700; padding: .18rem .55rem;
  border-radius: 999px; white-space: nowrap;
}
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.info { background: var(--blue-soft); color: var(--blue); }
.pill.mute { background: #eef0f3; color: var(--muted); }

.empty { color: var(--muted); font-style: italic; padding: .6rem 0; }

/* flash */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .93rem; }
.flash.ok { background: var(--green-soft); color: var(--green); }
.flash.error { background: var(--red-soft); color: var(--red); }

/* review page */
body.wide main { max-width: 1500px; }
.reviewgrid { display: grid; grid-template-columns: minmax(240px, 0.75fr) minmax(430px, 1.45fr); gap: 1.5rem; align-items: start; }
@media (max-width: 1000px) { .reviewgrid { grid-template-columns: 1fr; } }

/* --- the scoresheet, laid out like the printed one ------------------- */
table.grid.header td input { width: 100%; }
table.grid.header { max-width: 34rem; }

/* Exactly two halves — home and away — side by side when the space allows,
   stacked when it doesn't. Sized against the container, not the viewport,
   because the sheet sits in a column next to the scan. */
.sheetwrap { container-type: inline-size; }
.halves { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@container (max-width: 640px) { .halves { grid-template-columns: 1fr; } }
@supports not (container-type: inline-size) {
  @media (max-width: 980px) { .halves { grid-template-columns: 1fr; } }
}
.teamhalf { min-width: 0; }
.teamhalf h4 {
  margin: 0 0 .35rem; font-size: .9rem; display: flex; justify-content: space-between;
  align-items: baseline; gap: .5rem;
}
.teamhalf h4 span { font-weight: 400; color: var(--muted); font-size: .76rem; white-space: nowrap; }

table.sheet { border-collapse: collapse; width: 100%; background: #fff; table-layout: fixed; }
table.sheet th {
  background: #1b1c20; color: #fff; font-size: .62rem; letter-spacing: .03em;
  padding: .3rem .15rem; font-weight: 700;
}
table.sheet td { border: 1px solid #d7dade; padding: 0; text-align: center; font-size: .85rem; }

/* Column widths live on the colgroup because table-layout is fixed.
   PLAYER NAME is left unset so it absorbs the remaining space. */
col.c-rnd  { width: 22px; }
col.c-slot { width: 26px; }
col.c-type { width: 62px; }
col.c-stat { width: 30px; }
col.c-race { width: 46px; }
col.c-hcp  { width: 36px; }
col.c-wl   { width: 54px; }
col.c-cum  { width: 44px; }

td.rnd {
  background: #1b1c20; color: #fff; font-size: .58rem; letter-spacing: .07em;
  writing-mode: vertical-rl; transform: rotate(180deg); padding: .2rem 0;
  white-space: nowrap;
}
/* Blue = the side that broke, matching the sheet's shaded columns. */
tr.brk td:not(.rnd) { background: #a9e1f1; }

td.slot { font-weight: 600; background: #f1f2f5; color: #555; }
td.nm { text-align: left; }
td.nm input {
  border: 0; background: transparent; width: 100%; font: inherit;
  padding: .26rem .35rem; text-align: center;
}
td.nm input:focus { background: #fffbdd; outline: 1px solid #b9a94a; }
td.nm input.partner {
  border-top: 1px dashed #d7dade; font-size: .78rem; color: #444;
}
/* Who a short or scrawled grid name was matched to on the roster —
   shown so the join is visible, while the input keeps what the paper says.
   Exactly ONE line, ellipsized (full name in the tooltip): a wrapping
   annotation would make this row taller than its twin on the other half of
   the sheet, and the two halves must stay level row for row. */
td.nm .asread {
  display: block; font-size: .7rem; color: var(--muted);
  padding: 0 .35rem .2rem; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* The team headers likewise: a long decorated team name wrapping on one
   side would push that whole half down before the grid even starts. */
.teamhalf h4 {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
td.hcp { color: var(--muted); font-size: .8rem; }
td.gtype input {
  border: 0; background: transparent; width: 100%; font: inherit;
  font-size: .76rem; padding: .22rem .2rem; text-align: center;
}
td.gtype input:focus { background: #fffbdd; outline: 1px solid #b9a94a; }

/* 9-ball only: Three Fouls / Break & Run are printed with a pale blue fill,
   and the RACE cell carries a pre-printed slash. */
td.stat { background: #dff2f9; }
td.stat input, td.race input {
  border: 0; background: transparent; width: 100%; font: inherit;
  font-size: .78rem; padding: .22rem .1rem; text-align: center;
}
td.race input::placeholder { color: #9aa3ad; }
td.stat input:focus, td.race input:focus { background: #fffbdd; outline: 1px solid #b9a94a; }
td.blindcol {
  background: #1b1c20; width: 1.35rem; text-align: center; padding: .2rem 0;
}
td.blindcol input { margin: 0; cursor: pointer; }

td.wl select, td.wl input {
  border: 0; background: transparent; font: inherit; font-weight: 700;
  padding: .2rem; width: 100%; text-align: center;
}
td.cum { font-weight: 600; }
td.cum input[type="number"] {
  border: 0; background: transparent; font: inherit; font-weight: 600;
  padding: .2rem 0; width: 100%; text-align: center;
  -moz-appearance: textfield;
}
td.cum input[type="number"]::-webkit-outer-spin-button,
td.cum input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}

/* Collapsed detail rows in the job lists, and the folded uploaded log. */
.jobmore summary {
  color: var(--muted); font-size: .8rem; cursor: pointer;
  list-style-position: inside;
}
.jobmore[open] summary { margin-bottom: .15rem; }
/* No display:flex here — flex on a <summary> strips its disclosure
   triangle in Chrome, and the triangle is the whole affordance. */
.uploadedlog > summary { cursor: pointer; margin: 1rem 0 .4rem; }
.uploadedlog > summary .pill { margin-left: .5rem; }
.uploadedlog .nighthead {
  margin: .7rem 0 .1rem; color: var(--muted); font-size: .85rem;
  text-transform: none;
}
.costline summary { cursor: pointer; }

.finalbox { display: flex; justify-content: flex-end; align-items: center; gap: .4rem; margin-top: .4rem; }
.finalbox b { background: #1b1c20; color: #fff; font-size: .62rem; letter-spacing: .05em; padding: .18rem .4rem; }
.finalbox input {
  width: 3.2rem; text-align: center; font: inherit; font-weight: 700;
  padding: .2rem; border: 1px solid var(--line); border-radius: 4px;
}
.scan img { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-bottom: .8rem; }

.issue {
  border-left: 4px solid var(--line); background: #fff;
  border-radius: 8px; padding: .75rem .9rem; margin-bottom: .7rem;
  border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.issue.sheet { border-left-color: var(--red); }
.issue.reading { border-left-color: var(--amber); }
.issue.info { border-left-color: var(--blue); }
.issue .t { font-weight: 700; }
.issue .d { font-size: .9rem; margin-top: .15rem; }
.issue .todo { font-size: .88rem; color: var(--muted); margin-top: .35rem; }
.issue details { margin-top: .3rem; }
.issue summary { cursor: pointer; }
ul.alsolist { margin: .35rem 0 .1rem; padding-left: 1.2rem; font-size: .87rem; color: var(--muted); }

table.grid { border-collapse: collapse; width: 100%; font-size: .9rem; background: #fff; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: .3rem .45rem; text-align: left; }
table.grid th { background: #f1f2f5; font-size: .8rem; }
table.grid input[type=text] { width: 100%; padding: .25rem .35rem; }
table.grid select { padding: .25rem; }

.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.2rem; }
.hint { color: var(--muted); font-size: .88rem; }
.setup { font-size: .9rem; }
.setup code {
  background: #eef0f3; padding: .12rem .35rem; border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace; font-size: .87em;
}
a.back { color: var(--blue); text-decoration: none; font-size: .9rem; }

/* --- reading a whole folder ------------------------------------------- */

/* The folder path is the one field where people paste something long, so it
   gets the full width and a monospace face — a stray space or a missing
   backslash is otherwise invisible. */
#folder { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .85rem; }

/* The folder form stacks rather than sitting on one line: the path field wants
   the full width, and its explanation has to sit under the button it explains
   rather than beside it. */
form.uploader:has(#folder) { display: block; }
form.uploader:has(#folder) .field { width: 100%; margin-bottom: .8rem; }
form.uploader:has(#folder) .hint { margin: .45rem 0 0; }

.checkline label {
  display: flex; align-items: center; gap: .45rem;
  font-size: .9rem; font-weight: 500;
}
.checkline input[type=checkbox] { width: auto; margin: 0; }

.orsep {
  display: flex; align-items: center; gap: .75rem;
  color: var(--muted); font-size: .85rem; margin: 1.4rem 0 1rem;
}
.orsep::before, .orsep::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

.notice {
  background: var(--amber-soft); border: 1px solid var(--amber);
  border-radius: 8px; padding: .8rem 1rem; margin: 1rem 0;
  font-size: .9rem; line-height: 1.5;
}

.btnlink { margin-left: .8rem; font-size: .9rem; }

/* One PDF can produce eight jobs. Without the page range they all render as
   the same filename and the operator cannot tell which is which. */
.jobsub .origin { color: var(--muted); }

/* --- what the tool is doing right now ---------------------------------- */

/* Reading a night's sheets takes a couple of minutes and almost all of it
   happens before the first match appears. Without something moving on screen,
   the director assumes the button didn't work and presses it again. */
.runbox {
  border: 1px solid var(--line); border-radius: 10px;
  padding: .9rem 1rem; margin: 1.2rem 0; background: var(--blue-soft);
}
.runbox.runfail { background: var(--red-soft); border-color: var(--red); }
.runhead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.runbox .hint { margin: .5rem 0 0; }

.bar {
  height: 8px; border-radius: 999px; background: #fff;
  overflow: hidden; margin-top: .6rem;
}
.bar span {
  display: block; height: 100%; background: var(--blue);
  transition: width .4s ease;
}

.skiplist { margin: .3rem 0 0 1.1rem; padding: 0; font-size: .85rem; color: var(--muted); }
.skiplist li { margin: .15rem 0; }

/* The one form: stacked, with the path box full width. */
form.onebutton { display: block; }
form.onebutton .field { width: 100%; margin-bottom: .2rem; }
form.onebutton .orsep { margin: 1rem 0; }
form.onebutton button { margin-top: .4rem; }
form.onebutton .hint { margin: .35rem 0 0; }
