/* `hidden` always hides: a class's display (grid, block) would otherwise beat the attribute (the Ref row, "was 3"). */
[hidden] { display: none !important; }
/* The admin page (admin-web.md §5): the app's light tokens, system fonts, desktop first. No inline styles anywhere:
   the CSP's style-src is 'self'. */

:root {
  --background: #eaf5ee;
  --surface: #ffffff;
  --text: #111111;
  --text-muted: #3d4a42;
  --primary: #1e7a4e;
  --on-primary: #ffffff;
  --primary-ink: #1a6b45;
  --primary-pressed: #145a39;
  --sage: #ddf0e3;
  --zebra: #f6fbf8;
  --accent-ink: #a8470c;
  --accent-soft: #fcebdd;
  --border: #c4ddcc;
  --danger: #a61b1b;
  --danger-soft: #fbe3e3;
  --amber: #b26b00;
  --amber-soft: #fff1d6;
  --grey: #5a6b60;
  --shadow: 0 1px 2px rgba(27, 111, 70, 0.14), 0 3px 10px rgba(27, 111, 70, 0.08);
  --control: 36px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--background);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary-ink); }
a:hover { color: var(--primary-pressed); }

:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }

h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.muted { color: var(--text-muted); }
.error { color: var(--danger); }
.notice { color: var(--text); }
.error:empty, .notice:empty { display: none; }
.mono, code, .id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

button, input, select { font: inherit; }

button {
  min-height: var(--control);
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover { background: var(--zebra); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--primary-pressed); }
button.quiet { border-color: transparent; background: transparent; color: var(--on-primary); }
button.quiet:hover { background: rgba(255, 255, 255, 0.16); }
button.more { margin-top: 12px; }

input[type="text"], input[type="password"], input[type="search"] {
  min-height: var(--control);
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
/* The device token is text, masked by CSS (§3, N5), so password managers leave it alone. */
input.masked { -webkit-text-security: disc; text-security: disc; }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  vertical-align: middle;
}
.tier-prod { background: var(--danger); color: #ffffff; }
.tier-stage { background: #f2b33d; color: #111111; }
.tier-dev { background: #d5dbd7; color: #111111; }
.chip.deleted { background: var(--danger-soft); color: var(--danger); letter-spacing: 0; font-weight: 600; }
/* Neutral chips (Custom, a player's own place) take the DEV grey, so they show on a white card (#425). */
.chip.own, .chip.neutral { background: #d5dbd7; color: #111111; letter-spacing: 0; font-weight: 600; }

/* Sign-in: a centred card, 400 wide at most. */
.signin-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.signin {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 14px;
}
.signin h1 { font-size: 20px; margin: 0; }
.field { display: grid; gap: 4px; }
.field label { font-weight: 600; }
.hint { margin: 0; font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
/* A field with Clear beside it (Edit place): Clear sends null (§7). */
.with-clear { display: flex; gap: 8px; align-items: center; }
.with-clear input { flex: 1; min-width: 0; }
.grid-tools { display: grid; gap: 10px; margin-bottom: 8px; }
/* The hole grid fits the drawer at every width: Hole and Par narrow, Name and Notes share the rest (§7, #427). */
table.hole-grid { border-collapse: collapse; width: 100%; table-layout: fixed; }
table.hole-grid th, table.hole-grid td { padding: 3px 4px; text-align: left; overflow: hidden; }
table.hole-grid th[scope=row] { text-align: right; color: var(--text-muted); font-weight: 500; }
table.hole-grid input { width: 100%; min-width: 0; box-sizing: border-box; }
table.hole-grid col.hole-n { width: 2.75em; }
table.hole-grid col.hole-par { width: 4em; }
/* Name and Notes split what's left evenly (pp-design, #427). */
table.hole-grid input.changed { border-left: 3px solid var(--amber); }
/* Edit scores and Edit pars (§7): a narrow numeric input per cell, "was 3" under a changed one. */
.drawer .grid-wrap { box-shadow: none; border: 1px solid var(--border); }
table.edit-grid { border-collapse: collapse; }
table.edit-grid th, table.edit-grid td { padding: 3px 6px; text-align: left; vertical-align: top; }
table.edit-grid th[scope=row] { text-align: right; color: var(--text-muted); font-weight: 500; }
/* A row's number sits level with the middle of its input, whatever "was" adds under it (pp-design, #429). */
table.edit-grid th[scope=row], table.hole-grid th[scope=row] { vertical-align: top; line-height: var(--control); }
/* §7's widths (#414 look-check): no column narrower than its input; headers wrap at spaces only; a removed player's
   read-only cells centred like the inputs; a grid too wide for the drawer scrolls with Hole kept in view. */
table.edit-grid th.player { min-width: 3em; max-width: 7em; white-space: normal; overflow-wrap: break-word; vertical-align: bottom; font-weight: 500; }
table.edit-grid th.player .tag { display: block; }
table.edit-grid .removed { color: var(--text-muted); }
table.edit-grid td.removed { min-width: 3em; text-align: center; line-height: var(--control); }
table.edit-grid thead th:first-child { vertical-align: bottom; }
table.edit-grid th[scope=row], table.edit-grid thead th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
table.edit-grid input { width: 3em; box-sizing: border-box; text-align: center; }
table.edit-grid input.changed { border-left: 3px solid var(--amber); }
table.edit-grid .was { display: block; font-size: 12px; line-height: 1.3; }
.signin .error, .signin .notice { margin: 0; }

/* The top bar: 56 tall, full width. */
.top {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--primary);
  color: var(--on-primary);
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.who, .top button { flex-shrink: 0; }
.who { margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.banner { margin: 0; padding: 10px 16px; font-weight: 600; }
.banner.danger { background: var(--danger); color: #ffffff; }
.banner.warning { background: var(--amber-soft); color: #111111; border-bottom: 1px solid #f2b33d; }
.banner code { font-weight: 400; }
/* A banner's Dismiss is a normal secondary button, never text on the banner's colour (§5, #426). */
.banner button.on-banner { margin-left: 8px; font-weight: 400; }

/* ≥ 1100: a 208 rail and content up to 1200. */
.frame { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.rail { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 8px; }
.rail ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rail a {
  display: flex;
  align-items: center;
  min-height: var(--control);
  padding: 0 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.rail a:hover { background: var(--zebra); }
.rail a[aria-current="page"] { background: var(--sage); color: var(--primary-ink); }
.content { padding: 24px; max-width: 1248px; width: 100%; outline: none; }

/* Tables at 15 px, rows 40 tall, zebra. */
table.list { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 8px 12px; height: 40px; vertical-align: middle; }
table.list th { font-size: 13px; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); }
table.list tbody tr:nth-child(even) { background: var(--zebra); }
ul.changes { list-style: none; margin: 0; padding: 0; overflow-wrap: anywhere; }
ul.changes li.changed { font-style: italic; color: var(--text-muted); }
.not-logged { font-style: italic; color: var(--text-muted); }
/* Two-line cells (Audit's When and Reason): narrow columns, each part on its own line, none wrapping. */
.two-line > span { display: block; white-space: nowrap; }
table.list td.tight, table.list th.tight { width: 1%; }
table.list td.wide { min-width: 200px; }
table.list td.break { overflow-wrap: anywhere; }
/* A filter chip with its × (Audit's admin filter). */
.chip.filter { background: var(--zebra); color: var(--text); font-weight: 600; letter-spacing: 0; padding: 1px 4px 1px 10px; }
.chip-x { border: 0; background: transparent; color: var(--text-muted); font: inherit; font-size: 15px; line-height: 1; padding: 2px 6px; margin-left: 2px; cursor: pointer; border-radius: 999px; }
.chip-x:hover, .chip-x:focus-visible { color: var(--text); background: var(--border); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { width: 320px; max-width: 100%; }
.check { display: inline-flex; gap: 6px; align-items: center; margin-left: 8px; }

/* Detail pages: facts in a two-column grid, label 160 and value, with History under them. */
.title-row { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.title-row h1 { margin: 0; }
.block { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 20px; margin-top: 16px; }
.block:has(> table.list) { background: transparent; box-shadow: none; padding: 0; }
/* History's heading sits outside the card, with rows or without; an empty one's line gets the card (pp-design #403). */
.block.history { background: transparent; box-shadow: none; padding: 0; }
.block.history > p { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 20px; margin: 0; }
.block-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.facts { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
button.id { min-height: 0; padding: 0 6px; font-size: 13px; border-radius: 6px; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* One place (§6 Places): its facts, then each course as a card with its versions' pars across. No map. */
.block-group > h2 { margin: 24px 0 0; }
.course .title-row { margin-top: 0; margin-bottom: 12px; }
.course .title-row h3 { margin: 0; }
.version { margin-top: 16px; }
.version > summary { margin: 0 0 8px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: 24px; }
.version .grid-wrap { box-shadow: none; border: 1px solid var(--border); }
.version p { margin: 8px 0 0; }
table.grid.pars th { text-align: left; color: var(--text-muted); font-weight: 600; }

/* Counts: stat tiles, 4 columns on a computer and 2 on a phone. */
.group { margin-bottom: 24px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 16px; display: grid; gap: 4px; align-content: start; }
.tile .label { color: var(--text-muted); font-size: 13px; font-weight: 600; }
.tile .num { font-size: 28px; font-weight: 700; }
.tile a .num, .tile a.num { color: var(--primary-ink); }
.tile .sub { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--text-muted); }
.tile .sub b { color: var(--text); }
.tile .sub li.bad, .tile .sub li.bad b { color: var(--danger); }

/* 600–1099: tabs under the top bar that scroll sideways; content full width, less 24 a side. */
@media (max-width: 1099px) {
  /* The rail's row is as tall as its tabs; the content takes the rest of a short page (pp-design #403). */
  .frame { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--border); padding: 8px 16px; overflow-x: auto; }
  .rail ul { display: flex; gap: 4px; }
  .rail a { white-space: nowrap; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* < 600: controls 44, table rows become stacked cards. */
@media (max-width: 599px) {
  :root { --control: 44px; }
  .content { padding: 16px; }
  /* The tabs wrap to a second row, never clipped (§5, #425). */
  .rail { overflow-x: visible; padding: 8px 12px; }
  .rail ul { flex-wrap: wrap; }
  .top { gap: 8px; padding: 0 8px 0 12px; }
  .top button.quiet { padding: 0 8px; }
  .who { font-size: 14px; }
  .who .rights { display: none; }
  .brand { font-size: 15px; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; }
  table.list { background: transparent; box-shadow: none; }
  table.list thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table.list tbody tr { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 8px 12px; margin-bottom: 10px; }
  table.list tbody tr:nth-child(even) { background: var(--surface); }
  table.list td { height: auto; padding: 3px 0; display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 8px; }
  table.list td::before { content: attr(data-label); color: var(--text-muted); font-size: 13px; }
  table.list td:empty { display: none; }
  table.list td.tight, table.list td.wide { width: auto; min-width: 0; }
  /* In a card every value sits in the value column, numbers too (§5, #426). */
  table.list td.num { text-align: left; }
  /* A section head's line (a deleted game's "Deleted by its players…") drops under the heading (#414 look-check). */
  .block-head > .hint { flex-basis: 100%; margin-bottom: 12px; }
  /* Its space goes under the line, not between it and the heading (pp-design, #436). */
  .block-head:has(> .hint) > h2 { margin-bottom: 0; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}

/* Under 400 the brand drops "admin": the tier chip says where you are. */
@media (max-width: 399px) {
  .brand-admin { display: none; }
}

/* ---------- Writes (§7): the action row, the drawer, the PROD confirm ---------- */

select, input[type="date"], input[type="datetime-local"] {
  min-height: var(--control);
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
button.danger { background: var(--danger); border-color: var(--danger); color: #ffffff; font-weight: 600; }
button.danger:hover { background: #8a1515; }
button.danger-quiet { color: var(--danger); border-color: var(--danger-soft); }
button.danger-quiet:hover { background: var(--danger-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.banner.ok { background: var(--sage); color: var(--primary-ink); border-bottom: 1px solid var(--border); }

.drawer { background: var(--surface); box-shadow: var(--shadow); padding: 16px 20px; margin-top: 16px; border-radius: 12px; }
.drawer-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer-head h2 { margin: 0; outline: none; overflow-wrap: anywhere; }
/* One column that can shrink below its content's width, so a wide grid scrolls in its box, not the drawer (#414). */
.drawer form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.drawer .fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
/* Edit game's first and last hole, side by side (§7). */
.drawer .field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 8em)); gap: 12px; }
.drawer fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0; padding: 10px 12px 12px; display: grid; gap: 10px; }
/* The fields and the reason, locked together while a Write is out or in doubt (#426 S1). */
.drawer fieldset.bare { border: 0; border-radius: 0; padding: 0; min-width: 0; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.drawer fieldset.bare:disabled { opacity: 0.7; }
.drawer legend { font-weight: 600; padding: 0 4px; }
.drawer .reason { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.drawer .reason legend { grid-column: 1 / -1; }
/* The Ref, a 36-character batch id, takes the whole row and its full width, with New batch beneath when they don't
   both fit (pp-design, #429). On a phone it scrolls inside its box. */
.drawer .reason [data-testid=reason-ref-row] { grid-column: 1 / -1; }
.drawer .reason [data-testid=reason-ref-row] .with-clear { flex-wrap: wrap; }
.drawer .reason #reason-ref { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; flex: 1 1 calc(36ch + 24px); max-width: 100%; }
.drawer .choices .check { margin-left: 0; }
/* A player's row: Edit, then Remove or Restore, side by side at the row's end (§7). */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { padding: 4px 10px; }
.drawer .actions { margin-top: 0; }
.drawer p.error { margin: 0; }
.preview:empty { display: none; }
.preview { background: var(--zebra); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.preview h3 { font-size: 15px; margin: 0 0 6px; }
.preview ul { margin: 0; padding-left: 18px; }
.preview .warnings { margin-top: 8px; color: #6b3f00; background: var(--amber-soft); border-left: 3px solid var(--amber); padding: 6px 8px 6px 24px; }

dialog.confirm { border: 0; border-radius: 12px; box-shadow: var(--shadow); padding: 20px 24px; max-width: min(440px, calc(100vw - 32px)); }
dialog.confirm::backdrop { background: rgba(17, 17, 17, 0.4); }
dialog.confirm h2 { margin: 0 0 8px; }
dialog.confirm p { margin: 0 0 16px; overflow-wrap: anywhere; }
dialog.confirm .actions { margin: 0; }

/* ≥ 1100: a drawer from the right, 480 wide, beside the thing it changes, which keeps its room. */
@media (min-width: 1100px) {
  .drawer { position: fixed; top: 56px; right: 0; bottom: 0; width: 480px; margin: 0; border-radius: 0; overflow-y: auto; border-left: 1px solid var(--border); padding: 20px 24px; z-index: 5; }
  .frame:has(.drawer) .content { padding-right: 504px; }
}

/* < 600: a full-screen sheet. */
@media (max-width: 599px) {
  .drawer { position: fixed; inset: 0; margin: 0; border-radius: 0; overflow-y: auto; z-index: 10; padding: 16px; }
  body:has(.drawer) { overflow: hidden; }
  .drawer .reason { grid-template-columns: minmax(0, 1fr); }
}

/* Photo read: the keys under the provider, the model in monospace. */
.keys { list-style: none; margin: 4px 0 0; padding: 0; font-size: 14px; }
.keys li.muted { color: var(--text-muted); }
.facts .error { color: var(--danger); font-weight: 600; }
.facts .hint { margin: 2px 0 0; }

/* Games: inline filters; the score grid stays a grid at every width and scrolls sideways when it's wide. */
.field-inline { display: inline-flex; align-items: center; gap: 6px; }
.sub-title { margin: 4px 0 0; }
.grid-wrap { overflow-x: auto; width: fit-content; max-width: 100%; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
/* Sized to its columns (pp-design #407): Hole and Par narrow, players 96-160 with long names wrapping. */
table.grid { border-collapse: collapse; width: auto; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 6px 12px; text-align: center; height: 36px; white-space: nowrap; }
table.grid thead th { font-size: 13px; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); }
table.grid tbody th { color: var(--text-muted); font-weight: 600; }
table.grid tbody tr:nth-child(even) { background: var(--zebra); }
table.grid tfoot th, table.grid tfoot td { border-top: 1px solid var(--border); font-weight: 700; }
table.grid td.from-game { text-decoration: underline dotted; }
table.grid thead th.player { min-width: 96px; max-width: 160px; white-space: normal; overflow-wrap: anywhere; vertical-align: bottom; }
table.grid .removed { color: var(--text-muted); font-weight: 400; }
.block:has(> .grid-wrap) { background: transparent; box-shadow: none; padding: 0; }
