/* One style for all staff pages (USE-6). Instance colours override the variables below
   from base.html; these defaults must match config/settings.py (a test compares them) and
   apply alone on the 500 page. Allowed and denied stay fixed so no instance can make them
   look alike. Sides use logical properties (inline-start/end), so right-to-left languages
   mirror. Phones get one stacked column; wider screens use the room (design track, D3 trial). */

:root {
  --primary: #0f766e; /* links, main buttons (white text) and the focus halo */
  --text: #1f2a29;
  --background: #f7faf9;
  --surface: #ffffff;
  --soft: #d5f2ec;
  --nav: #e9f1ef; /* navigation: sidebar and frame, top bar on phones */
  --field-border: #767676; /* 4.5:1 on white, well above the 3:1 controls need (WCAG 1.4.11) */
  --allowed: #1b5e20;
  --allowed-bg: #e8f5e9;
  --denied: #b00020;
  --denied-bg: #fdecee;
  --muted: #5f5f66; /* secondary text, 6.4:1 on white */
  --border: #e4e4e7;
  --hover: #f4f4f5;
  --radius: .75rem;
  --radius-sm: .5rem;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 1px 3px rgb(0 0 0 / .04);
  --tap: 2.5rem; /* mouse and keyboard */
  --page: 64rem;
}

/* Touch screens get 48px targets (WCAG 2.5.5). */
@media (pointer: coarse) { :root { --tap: 3rem; } }

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { font-size: 100%; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Navigation. One element, two layouts: a bar on top (phones, login page) and a sidebar
   at the inline start with an inset content panel (wide screens with a login). */

.icon {
  inline-size: 1.1rem;
  block-size: 1.1rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: .25rem .75rem;
  padding: .5rem 1rem;
  background: var(--nav);
  border-block-end: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
  min-height: var(--tap);
  color: var(--text);
  font-weight: 650;
  letter-spacing: -.01em;
  line-height: 1.25;
  text-decoration: none;
}
.brand-text { min-width: 0; }
.brand .subtitle { color: var(--muted); font-weight: 400; }

/* Phones: the desk tools as tabs, the Manage tools in a menu at the inline end. If the tabs
   ever do not fit, they wrap to a second line rather than scroll out of sight. */
.sidebar-nav { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.sidebar-nav ul { display: flex; flex-wrap: wrap; gap: .25rem; margin: 0; padding: 0; list-style: none; }
/* An entry with a short label (e.g. "Register") shows it on phones, the full one on wide screens. */
.sidebar-nav .wide-only, .sidebar-nav .label-long { display: none; }
.nav-menu { position: relative; margin-inline-start: auto; }
.nav-menu summary { list-style: none; cursor: pointer; }
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-menu summary.current, .nav-menu[open] summary { background: var(--hover); color: var(--text); }
.nav-menu ul { position: absolute; inset-inline-end: 0; inset-block-start: calc(100% + .25rem); z-index: 10; flex-direction: column; min-inline-size: 12rem; padding: .25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.sidebar-label { display: none; }
.sidebar-nav a, .nav-menu summary, .session .user {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex: none;
  min-height: var(--tap);
  padding: 0 .65rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: .925rem;
  font-weight: 500;
  text-decoration: none;
}
.sidebar-nav a:hover, .nav-menu summary:hover, .session .user:hover { background: var(--hover); color: var(--text); }
.sidebar-nav a[aria-current="page"], .session .user[aria-current="page"] { background: var(--hover); color: var(--text); font-weight: 600; }
/* A number beside an entry, e.g. bans due for review. White on primary, like main buttons. */
.sidebar-nav .count { margin-inline-start: auto; min-inline-size: 1.4rem; padding: 0 .4rem; border-radius: 999px; background: var(--primary); color: #ffffff; font-size: .75rem; font-weight: 700; line-height: 1.4rem; text-align: center; }

.session { grid-row: 1; grid-column: 2; display: flex; align-items: center; gap: .25rem; }
.session .user { padding-inline: .35rem .65rem; }
.avatar {
  display: grid;
  place-items: center;
  inline-size: 2rem;
  block-size: 2rem;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--surface);
  font-size: .85rem;
  font-weight: 700;
  flex: none;
}
.user-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name, .user-hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name { color: var(--text); font-weight: 600; }
.user-hint { font-size: .8rem; font-weight: 400; }

/* Log out sits beside the account on wide screens only; on phones it is on /settings. */
.session .logout { display: none; }
.icon-button { margin: 0; padding: 0; inline-size: var(--tap); box-shadow: none; }
.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Phones: the avatar and the location, so staff still see where check-ins land (CHK-7). */
@media (max-width: 40rem) {
  .brand { gap: .5rem; }
  .brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .session .user { padding-inline: 0 .35rem; max-inline-size: 10rem; }
  .user-name { display: none; }
  /* Narrower tabs, so the desk tools and Manage fit on one line on common phones. */
  .sidebar-nav a, .nav-menu summary { gap: .4rem; padding: 0 .5rem; }
  /* The desk tools show their icon only; the name stays for screen readers and is the link's
     name. Entries in the Manage menu keep their words. */
  .sidebar-nav > ul:not(.wide-only) a { justify-content: center; min-inline-size: var(--tap); }
  .sidebar-nav > ul:not(.wide-only) .nav-text { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .sidebar-nav > ul:not(.wide-only) .icon { inline-size: 1.35rem; block-size: 1.35rem; }
}

@media (min-width: 48rem) {
  .with-sidebar {
    display: grid;
    grid-template-columns: 16rem minmax(0, 1fr);
    min-height: 100vh;
    background: var(--nav);
  }
  .with-sidebar .sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    block-size: 100vh;
    padding: .75rem;
    background: none;
    border: none;
  }
  .with-sidebar .brand { padding: .25rem .35rem; }
  .with-sidebar .brand .sep { display: none; }
  .with-sidebar .brand .subtitle { display: block; font-size: .85rem; }
  .with-sidebar .sidebar-nav, .with-sidebar .sidebar-nav ul { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .with-sidebar .sidebar-nav .wide-only { display: flex; }
  .with-sidebar .sidebar-nav .label-long { display: inline; }
  .with-sidebar .label-short, .with-sidebar .nav-menu { display: none; }
  .with-sidebar .sidebar-nav a:hover, .with-sidebar .session .user:hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }
  .with-sidebar .sidebar-nav a[aria-current="page"], .with-sidebar .session .user[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); }
  .with-sidebar .sidebar-label { display: block; margin: 0; padding: 0 .65rem; font-size: .75rem; font-weight: 500; color: var(--muted); line-height: 2rem; }
  .with-sidebar .session { margin-block-start: auto; }
  .with-sidebar .session .user { flex: 1; min-width: 0; }
  .with-sidebar .session .logout { display: block; }
  .with-sidebar > main {
    width: auto;
    max-width: none;
    padding: 2rem 2.5rem 3rem;
    margin: .5rem;
    margin-inline-start: 0;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .with-sidebar > main > * { max-width: var(--page); }
}

/* Page */

main { width: 100%; max-width: var(--page); margin: 0 auto; padding: 2rem 2rem 3rem; }

h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; margin: 0 0 1.25rem; }
h2 { font-size: 1.15rem; font-weight: 600; letter-spacing: -.01em; margin: 0 0 .75rem; }
.card > h1 { font-size: 1.5rem; }

a { color: var(--primary); text-underline-offset: .15em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.card > :last-child, .card form > :last-child { margin-bottom: 0; }
.card form p, .card form > div { margin: 0 0 .25rem; }

/* Forms */

label { display: block; font-weight: 500; font-size: .95rem; margin-bottom: .35rem; }

input, select, textarea {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: .5rem .75rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

textarea { min-height: 6rem; }

input[type="checkbox"], input[type="radio"] {
  display: inline-block;
  width: 1.25rem;
  min-height: 1.25rem;
  margin: 0;
  margin-inline-end: .5rem;
  vertical-align: middle;
  accent-color: var(--primary);
}

/* Buttons: main (primary fill) and secondary (outline). */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: var(--tap);
  padding: .5rem 1.1rem;
  margin: 0 0 1rem;
  margin-inline-end: .5rem;
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  color: #ffffff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: pointer;
}
button:hover, .button:hover { filter: brightness(.92); }

button.secondary, .button.secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}
button.secondary:hover, .button.secondary:hover { filter: none; background: var(--hover); }


/* The dark outline is the focus indicator; the halo only adds colour and may fall below
   3:1 on an instance's background, so never drop the outline. */
:focus-visible {
  outline: .2rem solid var(--text);
  outline-offset: .15rem;
  box-shadow: 0 0 0 .45rem color-mix(in srgb, var(--primary) 35%, transparent);
}
/* Text fields show focus on every click, so the dark box was loud: a ring in the primary
   colour on the border instead, which theme.py keeps at 4.5:1 on surface and background. */
:is(input:not([type="checkbox"], [type="radio"]), select, textarea):focus-visible {
  outline: .125rem solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
  box-shadow: 0 0 0 .25rem color-mix(in srgb, var(--primary) 20%, transparent);
}

.error, .errorlist { color: var(--denied); font-weight: 600; }
.errorlist { list-style: none; padding: 0; margin: 0 0 .3rem; }
.helptext { display: block; color: var(--muted); font-size: .875rem; margin: -.7rem 0 1rem; }

/* Fields render with Django's own form markup ({{ form }}): label, help text, errors, then the
   field, so the hint is read before typing. A group of choices is a fieldset named by its
   legend. */
form .helptext { margin: -.15rem 0 .45rem; }

/* A checkbox field: the box at the inline start, its label beside it (a tap on the label
   toggles it), help text under the label. */
form div:has(> input[type="checkbox"]) { display: grid; grid-template-columns: auto 1fr; column-gap: .6rem; align-items: center; align-content: start; margin: 0 0 1rem; }
form div:has(> input[type="checkbox"]) > input { grid-column: 1; grid-row: 1; margin: 0; }
form div:has(> input[type="checkbox"]) > label { grid-column: 2; grid-row: 1; margin: 0; padding-block: .6rem; cursor: pointer; }
form div:has(> input[type="checkbox"]) > .helptext { grid-column: 2; margin: -.4rem 0 0; }
form div:has(> input[type="checkbox"]) > .errorlist { grid-column: 1 / -1; }

/* A group of choices, e.g. entitlements at registration: the legend reads like a label, each
   choice is a full-height tap target. */
form fieldset { border: none; padding: 0; margin: 0 0 1rem; min-inline-size: 0; }
form fieldset legend { padding: 0; font-weight: 500; font-size: .95rem; margin-block-end: .35rem; }
form fieldset label { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); margin: 0; font-weight: 400; cursor: pointer; }
form fieldset :is(input[type="checkbox"], input[type="radio"]) { margin: 0; }
/* Two short choices read as one control side by side: birth year or age band. */
form fieldset div:has(> div > label > input[name="age_given"]) { display: flex; flex-wrap: wrap; column-gap: 1.5rem; }

/* A service's registration box is a sub-option of "Only members granted it", the last choice
   above it: indented under it, and hidden while the service is for every member. */
form div:has(> input[name="grantable_at_registration"]) { margin-block-start: -1rem; padding-inline-start: 1.75rem; }
form:has(input[name="audience"][value="everyone"]:checked) div:has(> input[name="grantable_at_registration"]) { display: none; }
/* Birth year or age band (ADR 0011): only the chosen field shows; the server keeps only it. */
form:has(input[name="age_given"][value="band"]:checked) div:has(> input[name="birth_year"]),
form:has(input[name="age_given"][value="year"]:checked) div:has(> select[name="age_band"]) { display: none; }

/* The answer at the desk: readable at a glance, never colour alone. */

.result {
  display: flex;
  align-items: center;
  gap: .75rem;
  border-radius: var(--radius);
  border: 1px solid;
  padding: 1.5rem;
  margin: 0 0 1.25rem;
  font-size: 2rem;
  font-weight: 750;
  letter-spacing: -.02em;
  line-height: 1.2;
}
.result.allowed { background: var(--allowed-bg); color: var(--allowed); border-color: var(--allowed); border-inline-start-width: .5rem; }
.result.denied { background: var(--denied-bg); color: var(--denied); border-color: var(--denied); border-inline-start-width: .5rem; }
/* Entry denied tints the whole page red, so it reads even when the heading is scrolled away.
   Body on phones, the inset panel on wide screens; gone when the result clears. */
body:has(.result.banned), body:has(.result.banned) main { background: var(--denied-bg); }
.notice.denied { background: var(--surface); color: var(--denied); border: 1px solid var(--denied); font-weight: 600; }
/* "Next" on the desk page and on the result page without JavaScript. */
body:has(.result.banned) main :is(button, .button):not(.secondary) { background: var(--denied); color: #ffffff; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .6rem 1.25rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); font-size: .9rem; padding-block-start: .1rem; }
.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* Lists of several things (bans, services, locations, today's entitlements, grants) are tables:
   a muted header row, a line between rows. On a narrow screen a wide table scrolls inside its
   card, never the page. */
.table-scroll { position: relative; overflow-x: auto; margin: 0 0 1rem; } /* relative: holds a visually hidden heading */
table.list { inline-size: 100%; border-collapse: collapse; }
table.list th { text-align: start; color: var(--muted); font-size: .85rem; font-weight: 500; padding: .4rem .75rem; border-block-end: 1px solid var(--border); white-space: nowrap; }
table.list td { padding: .55rem .75rem; border-block-end: 1px solid var(--border); vertical-align: middle; }
table.list tbody tr:last-child td { border-block-end: none; }
table.list :is(th, td):first-child { padding-inline-start: 0; }
table.list :is(th, td):last-child { padding-inline-end: 0; }
table.list form { margin: 0; }
table.list button { margin: 0; }

/* Today's entitlements (T7): the issue state in the last cell. */
.entitlement-name { font-weight: 600; }
.entitlements .hint, .entitlements .not-yet { color: var(--muted); }
.entitlements form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; }
.entitlements .issued { color: var(--allowed); font-weight: 600; }
.entitlements .error { display: block; }

.who { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; margin: 0 0 1rem; }
.who a { color: var(--text); }

.links { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
.links a { display: inline-flex; align-items: center; min-height: var(--tap); font-weight: 500; }

.meta { font-size: .95rem; }

.notice { background: var(--soft); border-radius: var(--radius-sm); padding: .85rem 1rem; margin-bottom: 1.25rem; }
.notice a { color: var(--text); }
/* Messages after an action span the whole page, also where main is a grid. */
.flash { grid-column: 1 / -1; }

/* A small state note inside a card, e.g. "Banned" on the member page. */
.tag { display: inline-flex; align-items: center; gap: .35rem; margin: -.5rem 0 1rem; padding: .2rem .7rem; border-radius: 999px; font-size: .9rem; font-weight: 600; }
.tag.denied { background: var(--denied-bg); color: var(--denied); }

/* The member card (CARD-1): previewed on screen, printed by print-a6.css. */
.member-card {
  background: #ffffff;
  color: #000000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  text-align: center;
}
.member-card .qr svg { display: block; width: 100%; max-width: 16rem; height: auto; margin: 0 auto; }
.member-card p { margin: .4rem 0; }
.member-card .center { font-weight: 700; }
.member-card .number { font-size: 1.4rem; font-weight: 800; }
.member-card .url { font-family: monospace; font-size: .8rem; overflow-wrap: anywhere; }

/* Desk scanner (T5). */
/* Typed token: "Check in" and "Cancel" side by side; the form box steps aside so both are
   items of one row. On phones they stack, full width, with a gap. */
#type-token { display: flex; flex-wrap: wrap; align-items: center; column-gap: .5rem; }
#type-token > h2, #type-token label, #type-token input, #type-token .notice { flex-basis: 100%; }
#type-token form { display: contents; }
#type-token button { margin: 0; }
.scanner video { display: block; inline-size: 100%; max-block-size: 60vh; background: #000000; border-radius: var(--radius-sm); object-fit: cover; margin-bottom: 1rem; }
details > summary { cursor: pointer; min-height: var(--tap); padding-block: .7rem; font-weight: 600; }

/* Page layouts. Narrow pages (log in, errors, confirm) sit centred; the others use the width. */

.page-narrow:not(.with-sidebar) main { max-width: 28rem; padding-block-start: 4rem; }
.page-narrow main > * { max-width: 28rem; }
.page-form main > * { max-width: 52rem; }
.page-desk main > * { max-width: 60rem; }

.page-location .card form { display: inline-block; }

/* Phones: one column, buttons full width for the thumb. */
@media (max-width: 40rem) {
  main, .page-narrow main { padding: 1.25rem 1rem 2rem; }
  button, .button { display: flex; width: 100%; margin-inline: 0; }
  /* A button in a table row keeps its own width, so the row stays readable. */
  table.list button { display: inline-flex; width: auto; }
  /* Lookup results (LKP-1): each row stacks, the name on its own line, then the aids with
     their labels and Check in at the inline end, so the action never scrolls out of view. */
  table.lookup thead { display: none; }
  table.lookup tr { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem 1rem; padding-block: .6rem; border-block-end: 1px solid var(--border); }
  table.lookup tbody tr:last-child { border-block-end: none; }
  table.lookup td { padding: 0; border: none; }
  table.lookup td:first-child { flex-basis: 100%; font-weight: 600; }
  table.lookup td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: .85rem; }
  table.lookup td:last-child { margin-inline-start: auto; }
  .result { font-size: 1.75rem; padding: 1.25rem; }
  #type-token { row-gap: .75rem; }
  #type-token > h2, #type-token label, #type-token input, #type-token .notice { margin-block: 0; }
}

/* Wider screens use the room. */
@media (min-width: 48rem) {
  /* Desk: the start choice as two large tiles. */
  .page-desk #start { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; padding: 0; border: none; background: none; box-shadow: none; }
  .page-desk #start button { margin: 0; min-height: 10rem; font-size: 1.25rem; flex-direction: column; }
  .page-desk #type-token { max-width: 36rem; }
  .page-desk #scanner { max-width: 44rem; }

  /* Forms: fields in two columns, long ones across. */
  .page-form .card form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.5rem; }
  .page-form .card form > :not(div), .page-form .card form > div:has(textarea, fieldset) { grid-column: 1 / -1; }
  /* Hint and errors sit between label and input, so two fields side by side align at the
     bottom: the inputs line up and each label stays on its input. Checkboxes align at the top. */
  .page-form .card form { align-items: end; }
  .page-form .card form > div:has(> input[type="checkbox"]) { align-self: start; }
  .page-form .card form > :is(button, .button) { justify-self: start; }
}

/* Two pairs of facts per row once a card beside the sidebar has room for them; below, the
   values would wrap letter by letter. */
@media (min-width: 60rem) {
  .page-desk .facts, .page-member .facts { grid-template-columns: max-content 1fr max-content 1fr; }
}

/* Cards side by side only where the first keeps two pairs of facts per row: the sidebar takes
   16rem, so below this a second column squeezed the first to a word per line. */
@media (min-width: 80rem) {
  /* Member: details and card side by side. */
  .page-member main { display: grid; grid-template-columns: minmax(0, 40rem) minmax(0, 20rem); gap: 0 1.5rem; align-items: start; align-content: start; }
  .page-member main > .button { grid-column: 1 / -1; justify-self: start; }

  /* Card print page: instructions beside the card preview. */
  .page-card main { display: grid; grid-template-columns: minmax(0, 32rem) 22rem; gap: 0 1.5rem; align-items: start; align-content: start; }
  .page-card main > .button { grid-column: 1 / -1; justify-self: start; }
}
