/* Layout only: design comes later. */

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

:root {
  --card-min: 15rem; /* narrowest an event card may get */
  --card-gap: 1rem;
}

body {
  /* Four event cards wide (4 × 15rem + 3 × 1rem gaps = 63rem) plus the page
     padding and a little slack, so the grid never needs five columns and the
     column sits centred on wide screens. */
  max-width: 66rem;
  margin: 0 auto;
  padding: 0 1rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- page structure ------------------------------------------------ */

header nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
}

header nav form,
footer form {
  display: inline;
}

/* The staff area's sub-navigation: a row of section links, the current one
   marked with aria-current="page" (see templates/admin/_nav.html). Admin and
   promoter pages share it, since they share the one area at /admin. */
.section-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

.section-nav a[aria-current="page"] {
  font-weight: 700;
}

main > * + * {
  margin-top: 1rem;
}

footer {
  margin-top: 2rem;
}

/* ---- responsive event grid ---------------------------------------- */

.event-grid {
  display: grid;
  /* auto-fill: cards shrink to the viewport and grow to fill the column, which
     the page width above caps at four columns. */
  grid-template-columns: repeat(auto-fill, minmax(min(var(--card-min), 100%), 1fr));
  gap: var(--card-gap);
  margin: 1rem 0;
}

.event-card {
  display: flex;
  flex-direction: column;
  border: 1px solid #000;
  padding: 0.75rem 1rem;
  overflow-wrap: anywhere;
}

.event-card > :first-child {
  margin-top: 0;
}

.event-card > :last-child {
  margin-bottom: 0;
}

.event-card img {
  display: block;
}

/* ---- event page: the main picture beside the copy ------------------ */

/* The main image takes a third of the width on the right, with the details and
   the description flowing around it. The article is a flow root so the float is
   contained and the sections after the event stay where they were. */
.event-detail {
  display: flow-root;
}

.event-main-image {
  float: right;
  width: calc(100% / 3);
  margin: 0 0 1rem 1.5rem;
}

.event-main-image img {
  display: block;
  width: 100%;
}

/* A third of a phone screen is a postage stamp, so it goes full width there. */
@media (max-width: 40rem) {
  .event-main-image {
    float: none;
    width: 100%;
    margin: 0 0 1rem;
  }
}

/* ---- form rows (e.g. a time next to its date) ---------------------- */

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
}

/* A row switched off with the `hidden` attribute has to be said here too: the
   `display: flex` above would otherwise win over the browser's own rule for
   `[hidden]`, leaving a row on the page that the form script has hidden (the
   sales-end fields, the single-day fields). */
.field-row[hidden] {
  display: none;
}

/* Each field in the row shares the width, rather than sizing itself (which
   would leave a full-width input on a line of its own). */
.field-row > * {
  flex: 1 1 14rem;
}

/* The listing filters: the fields share the width and wrap on a small screen. */
form.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0 1rem;
}

form.filters > p {
  flex: 1 1 12rem;
  margin: 0.25rem 0;
}

/* A search box and its button: the box takes the room, the button keeps its size. */
form.filters > button {
  flex: 0 0 auto;
}

/* ---- main image crop control (event form) -------------------------- */

/* A window in the site's image shape with the picture behind it, moved by
   dragging. The numbers here are only cosmetic: what actually gets cropped is
   worked out from the hidden fields by the server (see app/images.py) and by
   event_form.js, which mirror each other. */
.crop-box {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 22rem;
  aspect-ratio: var(--crop-ratio, 1 / 1);
  background: #f2f2f2;
  border: 1px solid #ccc;
  cursor: grab;
  touch-action: none;
}

.crop-box[hidden],
[data-crop-field][hidden],
[data-crop-reset][hidden],
.crop-hint[hidden] {
  display: none;
}

/* Nothing to drag when the whole picture is shown, padded to fit. */
.crop-box.is-padded {
  cursor: default;
  background: repeating-conic-gradient(#f2f2f2 0% 25%, #fafafa 0% 50%) 50% / 16px 16px;
}

.crop-box:focus-visible {
  outline: 2px solid #06c;
  outline-offset: 2px;
}

.crop-box.is-dragging {
  cursor: grabbing;
}

.crop-box img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  pointer-events: none;
  user-select: none;
}

/* ---- tables and forms (admin and promoter areas) ------------------ */

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border: 1px solid #000;
  padding: 0.35rem 0.5rem;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

fieldset {
  border: 1px solid #000;
  margin: 0 0 1.5rem;
  padding: 0.75rem 1rem 1rem;
}

/* The whole page is 66rem across, which leaves a text box looking like a letterbox
   on a wide screen: the fields read better as a column two thirds that size. Narrow
   the window and they simply fill what there is. */
form fieldset {
  max-width: 44rem;
}

legend {
  padding: 0 0.25rem;
}

/* Free text fills the row, so it lines up with the description box instead of the
   browser's narrow default. Anything with a size of its own keeps it: drop-downs,
   dates and times are only as wide as what they hold, and checkboxes, radios, file
   pickers and buttons keep their own size. <p class="narrow"> holds the few numbers
   that read better small — a quantity, a price, a capacity. */
textarea,
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="tel"],
input[type="number"] {
  width: 100%;
}

/* A web address that is still the one made from the title reads as a default:
   greyed while the box isn't being edited, so it is clear it follows the title. */
.is-default:not(:focus) {
  color: #666;
}

.narrow input,
.narrow select {
  width: 6rem;
}

/* Money is typed in rather than nudged: a number field's arrows move it one
   `step` at a time, which for a price means a penny a time — too fiddly to be
   any use. Only the arrows go; it stays a number field, so a phone still offers
   the numeric keypad and the arrow keys still work. */
input.money {
  -moz-appearance: textfield;
  appearance: textfield;
}

input.money::-webkit-outer-spin-button,
input.money::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* A field holding the end of a web address: the fixed part sits to its left, and
   the box takes the rest of the row (wrapping under it on a narrow screen). */
.url-field {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
}

.url-field .url-prefix {
  display: flex;
  align-items: center;
  padding-right: 0.25rem;
  color: #555;
  white-space: nowrap;
}

.url-field input {
  flex: 1 1 12rem;
  width: auto;
}

input,
select,
textarea,
button {
  max-width: 100%;
}

/* ---- images -------------------------------------------------------- */

img {
  max-width: 100%;
  height: auto;
}

/* ---- rich-text fields --------------------------------------------- */

/* The block a description field sits in. The editor is hidden in the markup and
   revealed by richtext.js; the plain-text textarea below it is what a browser
   without JavaScript shows and submits (see app/static/richtext.js). */
.rich-text-block {
  margin: 0.75rem 0;
}

.rich-field[hidden] {
  display: none;
}

.rich-editor {
  min-height: 6rem;
}

/* The editor is a bordered box (Quill's own stylesheet draws it), so it lines up
   with the other fields rather than the browser's default text area look. */
.rich-editor.ql-container {
  font-size: 1rem;
  font-family: inherit;
}

.rich-help,
.rich-plain-link {
  margin: 0.25rem 0 0;
}

/* The toolbar is a row of Quill's sprite buttons; keep them from wrapping and
   give the keyboard focus a visible ring. */
.rich-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.rich-toolbar button:focus-visible {
  outline: 2px solid #06c;
  outline-offset: 2px;
}

/* A pressed format is marked by more than colour: Quill also tints it. */
.rich-toolbar button[aria-pressed="true"] {
  outline: 2px solid #06c;
  outline-offset: -2px;
}

.rich-editor:focus-visible,
.rich-editor .ql-editor:focus-visible {
  outline: 2px solid #06c;
  outline-offset: 1px;
}

/* The link dialog richtext.js adds: a native <dialog>, so it traps focus and
   closes on Escape without any help. */
.rich-link-dialog {
  max-width: 32rem;
  padding: 1rem 1.25rem;
  border: 1px solid #000;
}

.rich-link-dialog input {
  width: 100%;
}

.rich-link-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}



/* ---- saving events ------------------------------------------------- */

/* Text for screen readers only: base.html's status region, which save.js fills
   in after hearting an event without reloading the page. */
/* ---- forms posted in the background (see app/static/forms.js) ------ */

/* A field's message, whether the server sent it back with the page or a live
   check put it there. It sits between the label and the field, where a screen
   reader reaches it before the control it is about. */
.field-error {
  display: block;
  color: #a00;
  font-weight: 700;
}

.field-error[hidden] {
  display: none;
}

/* The box around the field itself, so what needs fixing is visible as well as
   readable. The label is next to the field rather than a block in this design,
   so the outline is the only change. */
[aria-invalid="true"] {
  outline: 2px solid #a00;
  outline-offset: 1px;
}

/* While a form is posted its button is disabled; this says it is busy rather
   than broken, and stops a second press from sending it twice. */
form[aria-busy="true"] {
  cursor: progress;
}

form[aria-busy="true"] input,
form[aria-busy="true"] select,
form[aria-busy="true"] textarea {
  opacity: 0.7;
}

/* A message shown after a post made in the background joins the page's usual
   flash list, which has no style of its own; an error is marked out. */
.flashes .error {
  color: #a00;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The heart sits at the foot of the card, which is a column flexbox. */
.event-card .save-form {
  margin-top: auto;
}

.save-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid #000;
  background: none;
  cursor: pointer;
  font: inherit;
}

.save-button .save-icon {
  font-size: 1.1em;
  line-height: 1;
}

/* A saved event is marked by a filled-in heart and the word "Saved" as well as
   colour, so its state doesn't rely on seeing the difference between the two. */
.save-button[aria-pressed="true"] {
  font-weight: 700;
}

.save-button[aria-pressed="true"] .save-icon {
  color: #c00;
}

.save-button:focus-visible {
  outline: 2px solid #06c;
  outline-offset: 2px;
}



/* ---- the promoter's preview of a public event page ----------------- */

/* templates/promoter/event.html shows the public listing inside this box, using
   the same template the public page does (templates/public/_event_page.html). */
.preview {
  border: 1px dashed #888;
  padding: 0.5rem 1rem 1rem;
}

/* ---- flyers and photos: a small gallery ---------------------------- */

/* Templates lay the extras out as thumbnails (templates/public/_event_page.html);
   clicking one opens the picture itself, in place, via gallery.js. */
.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
  padding: 0;
  list-style: none;
}

.gallery figure {
  margin: 0;
}

/* A flyer is usually a poster, so the thumbnail fits the whole picture into a
   small box rather than cropping it. */
.gallery img {
  display: block;
  width: 7rem;
  height: 7rem;
  object-fit: contain;
  background: #f2f2f2;
  border: 1px solid #ccc;
}

.gallery figcaption {
  max-width: 7rem;
  font-size: 0.8rem;
}

.gallery a:focus-visible {
  outline: 2px solid #06c;
  outline-offset: 2px;
}

/* The pictures just chosen in the event form (see app/static/image_input.js),
   listed as the gallery shows them: a small box each, with the file's name, so
   it is clear what will be added when the event is saved. */
.chosen-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
  padding: 0;
  list-style: none;
}

.chosen-images[hidden] {
  display: none;
}

.chosen-images li {
  max-width: 7rem;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.chosen-images img {
  display: block;
  width: 7rem;
  height: 7rem;
  object-fit: contain;
  background: #f2f2f2;
  border: 1px solid #ccc;
}

/* The picture the viewer opened, at its own size: never enlarged past its
   resolution, and scaled down only when it is too big for the window. */
.gallery-viewer {
  max-width: 92vw;
  max-height: 92vh;
  padding: 0;
  border: 0;
  background: none;
}

.gallery-viewer img {
  display: block;
  width: auto;
  height: auto;
  max-width: 92vw;
  max-height: 92vh;
}

.gallery-viewer::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

/* ---- media players (YouTube, Vimeo, SoundCloud) -------------------- */

/* The markup is built by app/richtext.py from a link the promoter wrote; see the
   "Rich-text descriptions" section of the README. clear keeps a player below the
   floated event picture rather than under it. */
.embed {
  display: block;
  clear: both;
  width: 100%;
  max-width: 32rem;
  margin: 0.75rem 0;
  border: 0;
}

.embed-video {
  aspect-ratio: 16 / 9;
}

.embed-audio {
  height: 10.5rem; /* SoundCloud's own player height */
}

/* ---- venue locations (see app/static/venue_map.js) ------------------ */

.location-picker {
  margin: 0.5rem 0;
}

/* Leaflet needs a height on its container; width follows the page. The map is
   hidden in the markup and revealed by the script, so there is nothing to style
   for the no-JavaScript case. */
.location-map .map,
.venue-map .map {
  height: 20rem;
  width: 100%;
}

.location-map .map {
  margin-bottom: 0.5rem;
}

.venue-map {
  margin: 1rem 0;
  max-width: 40rem;
}

.location-choices select {
  max-width: 100%;
}

/* The lookup's feedback line: a polite live region (see the macro in
   _macros.html) that takes up no space in the page until it has something to
   say. */
[data-location-status]:empty {
  display: none;
}

