/* A table that opens locked, such as a master table (the page config's `identity.me.locked`,
   js/MasterLock.js), and the host's links beside the way back (`identity.links`). The table page
   (templates/table/table_detail.html) always links this file. A card in the top right corner says
   why the table is locked and unlocks it. Unlocked, a warning pill takes its place for as long as
   editing is on. Like table.css it uses the Bootstrap variables with PhaseSix-like fallbacks, and
   the warning colour marks the caution in every brand. */

/* ---- Back links: the way back, and the host's links beside it (a preview, say) ------------- */

.table-back-links {
  position: fixed;
  top: 12px;
  left: 16px;
  z-index: var(--table-z-back-link);
  display: flex;
  gap: 8px;
  /* The lock's corner stays free. */
  max-width: calc(100% - 32px - 356px);
}

.table-back-links .table-back-link {
  position: static;
  flex: 0 1 auto;
  min-width: 0;
  max-width: none;
}

.table-back-links .table-back-link--more {
  flex: none;
  color: var(--bs-secondary-color, #9aa4b2);
}

.table-back-links .table-back-link--more:hover,
.table-back-links .table-back-link--more:focus-visible {
  color: var(--bs-primary, #4f8fdb);
}

body:has(.table-root.is-denied) .table-back-links {
  display: none;
}

/* ---- The lock: card (locked) and pill (unlocked) --------------------------------------------- */

.table-masterlock {
  --masterlock-rgb: var(--bs-warning-rgb, 255, 193, 7);
  --masterlock-text: var(--bs-warning-text-emphasis, #ffda6a);
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: var(--table-z-back-link);
  display: flex;
  justify-content: flex-end;
  width: min(340px, calc(100% - 32px));
  font-family: var(--bs-body-font-family, system-ui, sans-serif);
  /* Only the card and the pill take input: the table shows through beside the pill. */
  pointer-events: none;
}

.table-masterlock[hidden],
.table-masterlock [hidden] {
  display: none !important;
}

.table-masterlock > * {
  pointer-events: auto;
}

/* Beside an open character or foe panel, like the HUD bar. */
.table-root.has-character-panel .table-masterlock {
  right: calc(var(--table-character-panel-width) + 16px);
}

.table-masterlock__card {
  position: static;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  align-items: start;
  width: 100%;
  max-height: none;
  padding: 14px 16px 16px;
  overflow: visible;
  background: rgba(var(--table-panel-rgb), 0.96);
  border-color: rgba(var(--masterlock-rgb), 0.6);
  box-shadow:
    0 12px 32px rgba(var(--table-black-rgb), 0.5),
    0 0 0 1px rgba(var(--masterlock-rgb), 0.12),
    0 0 28px rgba(var(--masterlock-rgb), 0.14);
  animation: table-masterlock-in 240ms ease-out;
}

.table-masterlock__sigil {
  grid-row: 1 / span 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--masterlock-text);
  background: radial-gradient(circle, rgba(var(--masterlock-rgb), 0.2), transparent 70%);
  border: 1px solid rgba(var(--masterlock-rgb), 0.5);
  border-radius: 50%;
}

.table-masterlock__sigil svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.table-masterlock__title {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--masterlock-text);
}

.table-masterlock__text {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--table-text);
}

.table-masterlock__actions {
  display: flex;
  margin-top: 8px;
}

.table-masterlock__unlock,
.table-masterlock__lock {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

/* The one way to start editing: filled in the warning colour, dark text on it. */
.table-masterlock__unlock {
  min-height: 36px;
  padding: 6px 16px;
  font-weight: 600;
  color: var(--bs-black, #000);
  background: rgba(var(--masterlock-rgb), 0.9);
  border-color: rgba(var(--masterlock-rgb), 1);
}

.table-masterlock__unlock:hover:not(:disabled),
.table-masterlock__unlock:focus-visible {
  background: rgba(var(--masterlock-rgb), 1);
}

.table-masterlock__unlock:focus-visible,
.table-masterlock__lock:focus-visible {
  outline: 2px solid var(--masterlock-text);
  outline-offset: 2px;
}

.table-masterlock__pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  max-width: 100%;
  padding: 3px 4px 3px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--masterlock-text);
  /* The warning tint over the panel colour: readable on every map. */
  background:
    linear-gradient(rgba(var(--masterlock-rgb), 0.16), rgba(var(--masterlock-rgb), 0.16)),
    rgba(var(--table-panel-rgb), 0.94);
  border: 1px solid rgba(var(--masterlock-rgb), 0.7);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(var(--table-black-rgb), 0.4);
  animation: table-masterlock-in 240ms ease-out;
}

.table-masterlock__pill svg {
  flex: none;
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.table-masterlock__label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.table-masterlock__lock {
  flex: none;
  min-height: 28px;
  padding: 3px 12px;
  font-weight: 400;
  color: var(--table-text);
  background: rgba(var(--table-panel-rgb), 0.7);
  border-color: rgba(var(--masterlock-rgb), 0.45);
  border-radius: 999px;
}

.table-masterlock__lock:hover:not(:disabled),
.table-masterlock__lock:focus-visible {
  background: rgba(var(--masterlock-rgb), 0.24);
}

@keyframes table-masterlock-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .table-masterlock__card,
  .table-masterlock__pill {
    animation: none;
  }
}

/* Fingers get 44 px targets. */
@media (pointer: coarse) {
  .table-masterlock__unlock,
  .table-masterlock__lock {
    min-height: 44px;
  }

  .table-masterlock__pill {
    padding-block: 2px;
  }
}

/* Beside an open GM info card the lock card folds to one row, title and button, like the pill:
   a GM info card never starts above 56 px (`EDGE + 40` in `place` of js/GmInfoCard.js; keep the
   two in step), so a row of at most 44 px at the top never covers it. The text is still the
   card's description for assistive technology, and it is back as soon as the GM info closes.
   Phones need none of it: the GM info is a bottom sheet there. */
@media (min-width: 577px) {
  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    width: auto;
    max-width: 100%;
    padding: 3px 4px 3px 14px;
    animation: none;
  }

  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__sigil,
  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__text {
    display: none;
  }

  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__title {
    margin: 0;
    white-space: nowrap;
  }

  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__actions {
    margin: 0;
  }

  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__unlock {
    min-height: 28px;
    padding: 3px 12px;
  }
}

/* With 44 px targets the row is taller: it moves up to stay above the GM info card. */
@media (min-width: 577px) and (pointer: coarse) {
  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock {
    top: 4px;
  }

  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__card {
    padding-block: 2px;
  }

  .table-root:has(.table-gminfo-card:not([hidden])) .table-masterlock__unlock {
    min-height: 44px;
  }
}

/* Phones: the links take the first row, the lock the one below it, across the screen. */
@media (max-width: 576px) {
  .table-back-links {
    max-width: calc(100% - 32px);
  }

  .table-masterlock {
    top: 54px;
    width: calc(100% - 32px);
  }
}
