/* Race Times: one stylesheet, no framework (slice 7).

   Every colour is a token here in :root, so the site's look can be changed in
   one place - a club's own colours, say. races/test_styles.py checks that no
   colour is written anywhere else, and that the text colours stay readable
   (WCAG AA) on the backgrounds they are used on. */
:root {
  --navy: #0f2a44;           /* header band, headings */
  --accent: #0a6194;         /* links, buttons, the current choice */
  --accent-strong: #084a72;  /* hover and pressed */
  --accent-soft: #e5f0f7;    /* the followed boat, the next handicap */
  --page: #f2f5f8;           /* behind everything */
  --surface: #ffffff;        /* cards, tables, rows */
  --text: #1b2733;
  --muted: #566371;          /* secondary text, discarded scores */
  --border: #d8dfe6;         /* separators and card edges */
  --field-border: #7b8794;   /* the edge of an input: must stand out (3:1) */
  --th-bg: #eef2f6;          /* table header row */
  --header-link: #dbe7f2;    /* links on the navy band */
  --ok: #1e6b3b;             /* saved, published */
  --ok-bg: #e6f4ea;
  --err: #b3261e;            /* errors */
  --err-bg: #fcebea;
  --warn: #7a4a00;           /* provisional, amended, notes */
  --warn-bg: #fff3d6;
  --shadow: 0 1px 2px rgb(15 42 68 / 0.06), 0 2px 8px rgb(15 42 68 / 0.05);
  --radius: 10px;
  --radius-small: 6px;
  --gap: 1rem;
  --tap: 44px;               /* smallest comfortable touch target on a phone */
}

/* --- Page and type ----------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
/* A hidden element stays hidden even when a rule here gives it a display (the race clock does). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}
.wrap { max-width: 60rem; margin: 0 auto; padding: 0 var(--gap); }
main.wrap { padding-top: 1.5rem; padding-bottom: 3rem; }
.site-footer { border-top: 1px solid var(--border); padding: 1rem 0 2rem; font-size: 0.875rem; }
.site-footer a { margin-right: 1.25rem; }

h1, h2, h3 { color: var(--navy); line-height: 1.25; margin: 1.5rem 0 0.5rem; }
h1 { font-size: 1.85rem; margin-top: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h2 small { font-size: 0.85rem; font-weight: normal; margin-left: 0.4rem; }
p { margin: 0.5rem 0 0.9rem; }

a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { color: var(--accent-strong); }
.muted { color: var(--muted); }
.discarded { color: var(--muted); }
abbr[title] { text-decoration: none; cursor: help; }

/* Keyboard users always see where they are. */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* --- Header ------------------------------------------------------------------ */

.site-header { background: var(--navy); color: var(--surface); }
.site-header .wrap {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.25rem 1rem; min-height: 3.5rem;
}
.site-header a { color: var(--header-link); text-decoration: none; }
.site-header a:hover { color: var(--surface); text-decoration: underline; }
.site-header :focus-visible { outline-color: var(--surface); }
.brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.15rem; }
.site-header a.brand { color: var(--surface); }
.brand img { width: 1.6rem; height: 1.6rem; }
/* Slice 11: the club's name leads; the service's name follows, smaller. */
.brand-service {
  font-size: 0.75rem; font-weight: 500; color: var(--header-link); letter-spacing: 0.02em;
  white-space: nowrap;
}
/* A long club name wraps beside the sail, and "Race Times" drops under it rather than squeezing. */
.brand-text { display: inline-flex; flex-wrap: wrap; align-items: baseline; column-gap: 0.5rem; }
.site-header nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1.1rem; }
.site-header nav form { display: inline; margin: 0; }
.site-header button.link { color: var(--header-link); text-decoration: none; }
.site-header button.link:hover { color: var(--surface); text-decoration: underline; }

/* --- Buttons and fields ---------------------------------------------------------- */

button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.5rem; padding: 0.45rem 1.1rem;
  border: 1px solid var(--accent); border-radius: var(--radius-small);
  background: var(--accent); color: var(--surface);
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer;
}
button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:active { transform: translateY(1px); }
button.secondary { background: var(--surface); color: var(--accent); }
button.secondary:hover { background: var(--accent-soft); color: var(--accent-strong); }
button.link {
  min-height: 0; padding: 0; border: none; background: none; color: var(--accent);
  font-weight: normal; text-decoration: underline; text-underline-offset: 0.15em;
}
button.link:hover { background: none; color: var(--accent-strong); }
button + button { margin-left: 0.5rem; }

/* :where() keeps this at zero specificity, so a form's own sizes win over it. */
:where(input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea) {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--field-border); border-radius: var(--radius-small);
  padding: 0.4rem 0.6rem; min-height: 2.5rem; max-width: 100%;
}
input[type=checkbox] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); vertical-align: middle; }
select { padding-right: 0.3rem; }
label { font-weight: 500; }

form.stacked p { margin: 0 0 1rem; }
form.stacked label { display: block; margin-bottom: 0.25rem; }
form.stacked input[type=checkbox] + label, form.stacked label:has(input[type=checkbox]) { display: inline; }
form.stacked input:not([type=checkbox]), form.stacked select, form.stacked textarea { width: 100%; max-width: 26rem; }
form.stacked .helptext { display: block; color: var(--muted); font-size: 0.875rem; margin-top: 0.2rem; }
form.stacked button { margin-top: 0.25rem; }

.errorlist { color: var(--err); margin: 0.25rem 0; padding-left: 1.1rem; font-size: 0.925rem; }

/* --- Messages, notes and labels ---------------------------------------------------- */

ul.messages { list-style: none; margin: 0 0 1.25rem; padding: 0; }
ul.messages li {
  padding: 0.65rem 0.9rem; margin-bottom: 0.4rem; border-radius: var(--radius-small);
  background: var(--ok-bg); border-left: 4px solid var(--ok);
}
ul.messages li.error { background: var(--err-bg); border-left-color: var(--err); }
ul.messages li.warning { background: var(--warn-bg); border-left-color: var(--warn); }
ul.messages li.info { background: var(--accent-soft); border-left-color: var(--accent); }

.note {
  background: var(--warn-bg); border-left: 4px solid var(--warn);
  padding: 0.65rem 0.9rem; border-radius: var(--radius-small);
}
.note p:first-child { margin-top: 0; }
.amended { color: var(--warn); }
/* Under the series standings: the date of the latest correction, in the body text colour. */
.standings-updated { color: var(--text); font-style: italic; }
.published { color: var(--ok); }
.provisional {
  display: inline-block; vertical-align: middle;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
  padding: 0.1rem 0.55rem; border-radius: 999px;
  color: var(--warn); background: var(--warn-bg); border: 1px solid var(--warn);
}
.next-handicap {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  padding: 0.65rem 0.9rem; border-radius: var(--radius-small);
}

/* --- Cards ------------------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 0.9rem 1.25rem; margin: 0.9rem 0;
}
.card h2, .card h3 { margin: 0.1rem 0 0.4rem; }
.card > :last-child { margin-bottom: 0; }
.card.has-errors { background: var(--err-bg); border-color: var(--err); }
.card.saved { background: var(--ok-bg); border-color: var(--ok); }
.card.publishing { border-left: 4px solid var(--accent); }
.card.publishing p { margin-top: 0; }
.card.publishing form > :last-child { margin-bottom: 0; }
table.proposed { width: auto; box-shadow: none; }
tr.changed td { font-weight: 600; background: var(--warn-bg); }
form.decision input { width: 100%; max-width: 30rem; margin-top: 0.25rem; }

/* --- Tables ------------------------------------------------------------------------ */

table { border-collapse: collapse; width: 100%; margin: 0.5rem 0 1rem; background: var(--surface); }
th, td { padding: 0.5rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--th-bg); color: var(--text); font-size: 0.9rem; font-weight: 700; letter-spacing: 0.02em; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.followed td { background: var(--accent-soft); }
tr.followed td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.table-scroll {
  overflow-x: auto; margin: 0.5rem 0 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.table-scroll table { margin: 0; }

/* --- The committee's rows: finish entry and the start sheet ---------------------------- */

.finish-row, .start-row {
  display: grid; gap: 0.6rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-small);
  padding: 0.6rem 0.8rem; margin-bottom: 0.5rem;
}
/* The time box is wide enough for a 12-hour clock with seconds ("07:30:05 PM"),
   which some browsers show depending on their language. */
.finish-row { grid-template-columns: 10rem 11.5rem 11rem 1fr auto; }
.start-row { grid-template-columns: 11rem 7rem 10rem auto; }
fieldset.start-rows { border: 0; margin: 0; padding: 0; min-width: 0; }
.finish-row.has-errors, .start-row.has-errors { background: var(--err-bg); border-color: var(--err); }
.finish-row.saved, .start-row.saved { background: var(--ok-bg); border-color: var(--ok); }
.finish-row .figures, .start-row .figures { grid-column: 1 / -1; font-size: 0.9rem; }
.finish-row .figures { font-variant-numeric: tabular-nums; }
.finish-row .figures:empty, .start-row .figures:not(:has(*)) { display: none; }
.finish-row select, .finish-row input { width: 100%; }
.start-row label { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: normal; }
.start-row input[type=number] { width: 4.25rem; }
details.not-racing {
  margin-top: 1rem; padding: 0.6rem 0.8rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-small);
}
details.not-racing summary { cursor: pointer; font-weight: 600; color: var(--navy); }
#start-sheet-count { font-size: 1.05rem; }

/* --- Results pages ------------------------------------------------------------------ */

form.search { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
form.search label { flex-basis: 100%; }
form.search input { flex: 1; min-width: 0; max-width: 26rem; }
ul.matches { list-style: none; padding: 0; margin: 0.5rem 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
ul.matches li { padding: 0.55rem 0.9rem; border-bottom: 1px solid var(--border); }
ul.matches li:last-child { border-bottom: none; }
ul.link-list { list-style: none; padding: 0; margin: 0.5rem 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
ul.link-list li { border-bottom: 1px solid var(--border); }
ul.link-list li:last-child { border-bottom: none; }
ul.link-list a { display: block; padding: 0.6rem 0.9rem; text-decoration: none; font-weight: 500; }
ul.link-list a:hover { background: var(--accent-soft); }
/* The badge sits inside the link, so the whole row stays one click target;
   a small gap keeps it off the series name. */
ul.link-list a .final-badge { margin-left: 0.4rem; }
ol.podium { margin: 0.25rem 0 0; padding-left: 1.5rem; }
ol.podium li { padding: 0.1rem 0; }
.card h3 .provisional { margin-left: 0.3rem; }
/* Slice 10: a series declared final, in the published colours. */
.final-badge {
  display: inline-block; vertical-align: middle;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
  padding: 0.1rem 0.55rem; border-radius: 999px;
  color: var(--ok); background: var(--ok-bg); border: 1px solid var(--ok);
}
.series-links { margin-top: -0.25rem; }
/* Slice 15: links placed after the results they belong to. */
.end-links { margin-top: 1rem; }
form.follow {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 1.5rem 0 0.5rem; padding: 0.8rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
form.follow select { max-width: 100%; }
nav.race-picker { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1.75rem 0 0.5rem; }
nav.race-picker a {
  display: inline-flex; align-items: center; min-height: 2.25rem; padding: 0.3rem 0.95rem;
  border: 1px solid var(--accent); border-radius: 999px; background: var(--surface);
  text-decoration: none; font-weight: 500;
}
nav.race-picker a:hover { background: var(--accent-soft); }
nav.race-picker a[aria-current=page] { background: var(--accent); color: var(--surface); }
.detail-toggle { display: none; margin: 0.25rem 0; }
section.boat-series { margin-top: 2rem; }
table.boat-races td:first-child { white-space: nowrap; }

/* --- Phones ---------------------------------------------------------------------------
   On a phone a race shows place, boat, corrected time and points; the rest is
   one tap away under "More detail", a plain link that adds ?detail=1. The
   boat page's corrected times are on the series page, a tap away. Anything
   tapped is at least --tap tall. */
@media (max-width: 40rem) {
  h1 { font-size: 1.55rem; }
  main.wrap { padding-top: 1rem; }
  .site-header nav { gap: 0 0.75rem; font-size: 0.9rem; }
  .site-header nav a, .site-header button.link { display: inline-flex; align-items: center; min-height: var(--tap); }
  .brand { min-height: var(--tap); }
  button, nav.race-picker a { min-height: var(--tap); }
  button.link { min-height: 0; }
  td button.link { min-height: var(--tap); }
  :where(input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select) { min-height: var(--tap); }
  .detail-toggle { display: block; }
  .detail-toggle a { display: inline-flex; align-items: center; min-height: var(--tap); }
  th, td { padding: 0.45rem 0.4rem; }
  table.race-results:not(.all-columns) .detail { display: none; }
  table.boat-races .detail { display: none; }
  .finish-row, .start-row { grid-template-columns: 1fr 1fr; }
  .card { padding: 0.8rem 0.9rem; }
}

/* --- The race day page (slice 9) ------------------------------------------------------ */

.race-clock {
  display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; align-items: baseline;
  background: var(--navy); color: var(--surface); border-radius: var(--radius);
  padding: 0.6rem 1rem; font-variant-numeric: tabular-nums;
}
.race-clock strong { font-size: 1.5rem; margin-left: 0.35rem; }
nav.view-tabs { display: flex; gap: 0.5rem; margin: 1rem 0; }
nav.view-tabs a {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0.3rem 1.1rem;
  border: 1px solid var(--accent); border-radius: 999px; background: var(--surface);
  text-decoration: none; font-weight: 600;
}
nav.view-tabs a[aria-current=page] { background: var(--accent); color: var(--surface); }
.panel-message {
  padding: 0.65rem 0.9rem; border-radius: var(--radius-small);
  background: var(--ok-bg); border-left: 4px solid var(--ok);
}
.panel-message.error { background: var(--err-bg); border-left-color: var(--err); }

.racing-row, .finished-row {
  display: grid; gap: 0.5rem 0.75rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-small);
  padding: 0.6rem 0.8rem; margin-bottom: 0.5rem;
}
.racing-row { grid-template-columns: 1fr auto auto; }
.finished-row { grid-template-columns: 2rem 1fr auto auto auto; }
.racing-row.has-errors, .finished-row.has-errors { background: var(--err-bg); border-color: var(--err); }
.finished-row.saved { background: var(--ok-bg); border-color: var(--ok); }
.racing-row .boat, .finished-row .boat { font-size: 1.1rem; }
.finished-row .order { font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.finished-row .time { font-variant-numeric: tabular-nums; }
.racing-row form.tap, .finished-row form.undo { margin: 0; }
/* Big enough to hit on a moving boat. */
button.finished { min-height: 3.25rem; min-width: 8.5rem; font-size: 1.1rem; }

details.finish-form { grid-column: auto; }
details.finish-form summary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); min-width: var(--tap); padding: 0 0.8rem; cursor: pointer; list-style: none;
  border: 1px solid var(--accent); border-radius: var(--radius-small); color: var(--accent); font-weight: 600;
}
details.finish-form summary::-webkit-details-marker { display: none; }
details.finish-form[open] { grid-column: 1 / -1; }
details.finish-form[open] summary { background: var(--accent-soft); }
details.finish-form form {
  display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: flex-end; margin-top: 0.6rem;
}
details.finish-form label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.9rem; }
details.finish-form .figures { flex-basis: 100%; }

@media (max-width: 40rem) {
  .racing-row { grid-template-columns: 1fr auto; }
  .racing-row .boat { grid-column: 1 / -1; }
  .racing-row form.tap button.finished { width: 100%; }
  /* Boat on the first line; time, Undo and Edit on the second. */
  .finished-row { grid-template-columns: 1.75rem 1fr auto auto; }
  .finished-row .boat { grid-column: 2 / -1; }
  .finished-row .time { grid-column: 2 / 3; }
  .race-clock strong { font-size: 1.25rem; }
}

/* --- The Members page (slice 11) ---------------------------------------------------- */
.member-row { display: grid; grid-template-columns: 1fr auto auto; gap: 0.6rem 1rem; align-items: center; margin-bottom: 0.6rem; }
.member-row .buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }
@media (max-width: 40rem) { .member-row { grid-template-columns: 1fr; } }
