/* Shared by the board pages and the admin pages: pop-up panels (.sheet),
   the add/edit form inside them (.edit-form), buttons, the admin bar, and
   the confirmation/error notice (.toast). Uses the colour tokens each page's
   own stylesheet defines (--ink, --rail, --chalk, --brass, --rose, --turf,
   --turf-stripe, --turf-deep). */

/* Confirmation and error notices, just above the prize footer */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 2.75rem);
  z-index: 20;
  max-width: calc(100vw - 2rem);
  margin: 0;
  padding: 0.5rem 0.9rem;
  border-radius: 3px;
  background: var(--ink);
  color: var(--rail);
  font-size: 0.95rem;
  font-weight: 600;
  font-stretch: 88%;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.5rem);
  transition: opacity 0.15s, transform 0.15s;
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error { background: var(--rose); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* All bets page: the full list of bets on one horse, opened by tapping a
   card whose names don't all fit */

.sheet {
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(34rem, 80dvh);
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--turf-deep);
  color: var(--chalk);
  box-shadow: 0 18px 40px -12px rgb(0 0 0 / 0.6);
}

.sheet[open] {
  display: flex;
  flex-direction: column;
  animation: sheet-open 0.16s ease-out;
}

.sheet::backdrop { background: rgb(15 36 25 / 0.6); }

@keyframes sheet-open {
  from { opacity: 0; transform: translateY(0.75rem) scale(0.98); }
}

.sheet__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.6rem 0.6rem 0.9rem;
  border-bottom: 2px solid var(--brass);
}

.sheet__title {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 0.4em;
  min-width: 0;
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  font-stretch: 72%;
  line-height: 1.1;
}

.sheet__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet__close {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: rgb(255 255 255 / 0.1);
  color: var(--chalk);
  cursor: pointer;
}

.sheet__close:focus-visible { outline: 2px solid var(--chalk); outline-offset: 2px; }

.sheet__list {
  flex: 1;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}

.sheet__list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0.9rem;
  font-size: 1.05rem;
  font-stretch: 88%;
}

.sheet__list li + li { border-top: 1px solid rgb(255 255 255 / 0.1); }

.sheet__bet,
.sheet__amount {
  color: var(--brass);
  font-weight: 850;
  font-stretch: 70%;
  font-variant-numeric: tabular-nums;
}

.sheet__total {
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 0.55rem 0.9rem 0.65rem;
  background: rgb(0 0 0 / 0.25);
  color: rgb(255 255 255 / 0.8);
  font-size: 1.05rem;
  font-stretch: 88%;
}

.sheet__amount { font-size: 1.2em; }

@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
}

/* Admin pages (/admin/horses, /admin/users) */

/* Under the header: what to do, and the Add button */
.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 0.45rem 0.4rem 0.6rem;
}

.admin-bar p {
  margin: 0;
  color: rgb(15 36 25 / 0.7);
  font-size: 0.9rem;
  font-stretch: 88%;
}

.admin-bar__add {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.35rem;
  height: 2.25rem;
  padding: 0 0.8rem 0 0.6rem;
  border: 0;
  border-radius: 3px;
  background: var(--ink);
  color: var(--chalk);
  font: inherit;
  font-weight: 700;
  font-stretch: 85%;
  cursor: pointer;
}

.admin-bar__add .icon { width: 1.2rem; height: 1.2rem; }

.admin-bar__add:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* The add/edit panel: builds on the .sheet panel */

/* hidden must win over the display: flex/grid set on parts of the panel */
.edit-form [hidden] { display: none !important; }

.sheet--form { width: min(30rem, calc(100vw - 2rem)); max-height: min(44rem, 90dvh); }

.edit-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.edit-form__body {
  display: grid;
  gap: 0.65rem;
  padding: 0.8rem 0.9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.edit-form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.edit-form__row--name { grid-template-columns: 5rem 1fr; }

.edit-form label {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
  color: rgb(255 255 255 / 0.8);
  font-size: 0.85rem;
  font-stretch: 88%;
}

.edit-form input[type="text"],
.edit-form input[type="number"] {
  width: 100%;
  height: 2.5rem;
  padding: 0 0.6rem;
  border: 2px solid transparent;
  border-radius: 3px;
  background: var(--chalk);
  color: var(--ink);
  font: inherit;
  font-size: 1rem; /* 16px stops iOS zooming in on focus */
  font-weight: 600;
  font-stretch: 88%;
}

.edit-form input:focus-visible {
  border-color: var(--brass);
  outline: none;
}

.edit-form .edit-form__check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--chalk);
  font-size: 1rem;
}

.edit-form__check input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--rose);
}

.edit-form__silk {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.edit-form__preview {
  display: grid;
  flex: none;
  place-items: center;
  width: 3rem;
  height: 3.6rem;
  border-radius: 3px;
  background: repeating-linear-gradient(120deg, var(--turf) 0 8px, var(--turf-stripe) 8px 16px);
}

.edit-form__preview img { width: 2.6rem; height: auto; }

.edit-form__hint {
  color: rgb(255 255 255 / 0.6);
  font-size: 0.85rem;
  font-stretch: 88%;
}

.edit-form__errors {
  margin: 0;
  padding: 0.5rem 0.7rem;
  border-radius: 3px;
  background: var(--rose);
  color: var(--chalk);
  font-size: 0.95rem;
  font-weight: 600;
}

.edit-form__actions,
.edit-form__confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem 0.8rem;
  background: rgb(0 0 0 / 0.25);
}

.edit-form__spacer { flex: 1; }

.edit-form__confirm {
  border-top: 2px solid var(--rose);
}

.edit-form__confirm p {
  flex: 1 1 100%;
  margin: 0 0 0.2rem;
  font-size: 0.95rem;
  font-stretch: 88%;
}

.button {
  height: 2.5rem;
  padding: 0 0.8rem;
  border: 0;
  border-radius: 3px;
  background: var(--brass);
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  font-stretch: 72%;
  cursor: pointer;
}

.button--quiet { background: rgb(255 255 255 / 0.12); color: var(--chalk); }
.button--danger { background: var(--rose); color: var(--chalk); }
.button:disabled { opacity: 0.5; cursor: progress; }

.button:focus-visible {
  outline: 2px solid var(--chalk);
  outline-offset: 2px;
}

/* Phones: Cancel and Save side by side, Delete on its own full-width row
   below, so the buttons never wrap unevenly */
@media (max-width: 599px) {
  .edit-form__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .edit-form__actions .edit-form__spacer { display: none; }
  .edit-form__actions [data-delete] {
    grid-column: 1 / -1;
    order: 1;
  }
}

/* Read-only fields (house odds, worked out from the bets) */
.edit-form input[readonly] {
  background: rgb(255 255 255 / 0.12);
  color: var(--chalk);
  cursor: default;
}

.edit-form__note {
  color: rgb(255 255 255 / 0.55);
  font-size: 0.78rem;
}
