/* QR Tracker — shared styles for the admin and tracking pages. */

:root {
  --bg: #edece6;
  --panel: #f5f4f0;
  --card: #ffffff;
  --ink: #1c2b29;
  --ink-soft: #55635f;
  --muted: #8a9693;
  --line: #e2e0d9;
  --line-soft: #eceae4;

  --teal: #1d4d47;
  --teal-hover: #163c37;

  --ok-bg: #dcefdd;
  --ok-ink: #2f6b3a;
  --share-bg: #e0e9ec;
  --share-ink: #3d5c65;
  --off-bg: #e6e5e0;
  --off-ink: #8a8a84;
  --danger: #b63a2b;
  --danger-hover: #932d21;

  --radius: 10px;
  --radius-lg: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/*
 * Views are shown and hidden via the `hidden` attribute. A class that sets
 * `display` (.login uses grid) would otherwise win over the attribute's
 * default `display: none`, leaving both views on the page at once.
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------------------------------------------------------------- buttons */

.btn {
  font: inherit;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn--primary { background: var(--teal); color: #fff; }
.btn--primary:hover:not([disabled]) { background: var(--teal-hover); }

.btn--ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn--ghost:hover:not([disabled]) { border-color: var(--muted); }

.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover:not([disabled]) { background: var(--danger-hover); }

.btn--block { width: 100%; }

/* ------------------------------------------------------------------ login */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.login__card {
  width: 100%;
  max-width: 21rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: 0 1px 2px rgba(28, 43, 41, .05);
}
.login__title { margin: 0 0 20px; font-size: 1.4rem; letter-spacing: -.01em; }

/* ------------------------------------------------------------------ fields */

.field { display: block; margin-bottom: 18px; }
.field__label { display: block; font-weight: 700; font-size: .85rem; margin-bottom: 6px; }
.field__optional { font-weight: 400; color: var(--muted); }
.field__hint { display: block; margin-top: 6px; font-size: .78rem; color: var(--muted); }

.field input {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.field input:focus-visible { outline: 2px solid var(--teal); outline-offset: 0; border-color: var(--teal); }

/* Password field with a reveal control sitting inside it. */
.input-reveal { position: relative; display: block; }
.input-reveal input { padding-right: 4.25rem; }

.input-reveal__btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
}
.input-reveal__btn:hover { color: var(--ink); }
.input-reveal__btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

/* A locked field (the slug, once the code exists) must not look editable. */
.field input:read-only {
  background: var(--panel);
  color: var(--ink-soft);
  cursor: not-allowed;
}
#field-code, #field-target, #delete-confirm { font-family: var(--mono); font-size: .9rem; }

.form-error {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: 8px;
  background: #fbeae7;
  color: var(--danger-hover);
  font-size: .85rem;
}

/* ------------------------------------------------------------------ admin */

.admin { max-width: 68rem; margin: 0 auto; padding: 40px 24px 64px; }

.admin__header {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px;
}
.admin__title { margin: 0; font-size: 1.9rem; letter-spacing: -.02em; }
.admin__actions { display: flex; gap: 10px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.panel__footnote { margin: 14px 2px 0; font-size: .78rem; color: var(--muted); }

.state { margin: 22px 2px; color: var(--muted); font-size: .9rem; }
.state--error { color: var(--danger-hover); }

/* Wide tables scroll inside the panel rather than the page. */
.table-scroll { overflow-x: auto; background: var(--card); border-radius: var(--radius); }

.codes { width: 100%; border-collapse: collapse; min-width: 54rem; }

.codes th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.codes td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.codes tbody tr:last-child td { border-bottom: 0; }
.codes tbody tr.is-off .cell-code,
.codes tbody tr.is-off .cell-url { color: var(--muted); }

.num { text-align: right; }
.cell-code { font-family: var(--mono); font-size: .85rem; font-weight: 600; white-space: nowrap; }
.cell-url { font-family: var(--mono); font-size: .82rem; color: var(--ink-soft); }
.cell-url a { color: inherit; text-decoration: none; }
.cell-url a:hover { text-decoration: underline; }
.cell-date { font-size: .84rem; color: var(--ink-soft); white-space: nowrap; }
.cell-scans { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.cell-actions { text-align: right; white-space: nowrap; }

/* -------------------------------------------------------- status badges */

.badge {
  font: inherit;
  font-size: .74rem;
  font-weight: 700;
  border: 0;
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s;
}
.badge:hover { filter: brightness(.95); }
.badge:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.badge--on { background: var(--ok-bg); color: var(--ok-ink); }
.badge--share { background: var(--share-bg); color: var(--share-ink); }
.badge--off { background: var(--off-bg); color: var(--off-ink); }
.badge[disabled] { cursor: wait; opacity: .6; }

.link-action {
  font: inherit;
  font-size: .84rem;
  font-weight: 700;
  background: none;
  border: 0;
  padding: 4px 6px;
  margin-left: 2px;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}
.link-action:hover { text-decoration: underline; }
.link-action:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
.link-action--danger { color: var(--danger); }
.link-action[aria-disabled="true"] { color: var(--muted); cursor: not-allowed; text-decoration: none; }

/* ------------------------------------------------------------------ modal */

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(32rem, calc(100vw - 32px));
  width: 100%;
}
.modal::backdrop { background: rgba(28, 43, 41, .45); }

/*
 * On a short viewport the form is taller than the screen. The head and foot
 * stay put and the body scrolls, so Cancel and Save are always reachable.
 */
.modal__card {
  background: var(--card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(28, 43, 41, .22);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 32px);
}

.modal__head, .modal__foot { flex: none; }

.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}
.modal__title { margin: 0; font-size: 1.2rem; letter-spacing: -.01em; }
.modal__close {
  border: 0; background: none; font-size: 1.5rem; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px;
}
.modal__close:hover { color: var(--ink); }

.modal__body { padding: 22px; overflow-y: auto; }
.modal__body .field:last-of-type { margin-bottom: 18px; }
.modal__warning { margin: 0 0 18px; font-size: .9rem; color: var(--ink-soft); }
.modal__warning strong { color: var(--ink); font-family: var(--mono); }

.modal__foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

/* ---------------------------------------------------------------- toggles */

.toggles { display: flex; flex-wrap: wrap; gap: 22px; margin-bottom: 18px; }

.toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__track {
  width: 42px; height: 24px; border-radius: 999px;
  background: #d4d2ca; position: relative; transition: background-color .15s;
  flex: none;
}
.toggle__track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}
.toggle input:checked + .toggle__track { background: var(--teal); }
.toggle input:checked + .toggle__track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle__track { outline: 2px solid var(--teal); outline-offset: 2px; }
.toggle__label { font-weight: 700; font-size: .9rem; }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: .87rem; font-weight: 600;
  box-shadow: 0 8px 22px rgba(28, 43, 41, .28);
  z-index: 10;
}
.toast--error { background: var(--danger-hover); }

@media (max-width: 640px) {
  .admin { padding: 26px 14px 48px; }
  .admin__title { font-size: 1.55rem; }
}

/* ======================================================= tracking page === */

.track { max-width: 60rem; margin: 0 auto; padding: 40px 24px 64px; }

.track__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 18px;
}
.track__head .eyebrow { margin: 0; }

.code-pill {
  font-family: var(--mono);
  font-size: .8rem;
  background: var(--share-bg);
  color: var(--share-ink);
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.admin-banner {
  margin: 0 0 18px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ok-bg);
  color: var(--ok-ink);
  font-size: .85rem;
  font-weight: 600;
}

/* Ad photo and QR card sit side by side, stacking on narrow screens. */
.track__media {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 15rem;
  gap: 18px;
  margin-bottom: 26px;
}

.photo {
  margin: 0;
  min-height: 17rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.photo__img { width: 100%; height: 100%; max-height: 24rem; object-fit: contain; display: block; }
.photo__empty { display: grid; gap: 8px; justify-items: center; color: var(--muted); font-size: .88rem; }
.photo__icon { font-size: 1.6rem; opacity: .55; }

.qr-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: center;
  justify-items: center;
}
.qr-card__img { width: 100%; max-width: 11rem; image-rendering: pixelated; }
.qr-card__pending {
  width: 100%; aspect-ratio: 1; max-width: 11rem;
  display: grid; place-items: center; text-align: center;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: .8rem;
  padding: 12px;
}
.qr-card .btn { text-align: center; text-decoration: none; }

.track__title { margin: 0 0 6px; font-size: 2rem; letter-spacing: -.02em; }
.track__target { margin: 0 0 24px; font-family: var(--mono); font-size: .88rem; color: var(--ink-soft); }
.track__target a { color: inherit; }

.track__disabled {
  margin: -14px 0 24px;
  font-size: .85rem;
  color: var(--off-ink);
}

/* ------------------------------------------------------------------ stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.stat__value {
  margin: 0 0 4px;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat__label { margin: 0; font-size: .85rem; color: var(--ink-soft); }

/* ---------------------------------------------------------- scan history */

.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 16px; padding: 0 2px;
}
.panel__title { margin: 0; font-size: 1.05rem; }

.scans-table { min-width: 34rem; }
.cell-place { font-size: .88rem; }
.cell-device { font-size: .88rem; color: var(--ink-soft); }

/* ----------------------------------------------------- not-shared notice */

.notice { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.notice__card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 26rem;
  text-align: center;
}
.notice__title { margin: 0 0 8px; font-size: 1.3rem; }
.notice__text { margin: 0; color: var(--ink-soft); font-size: .92rem; }

@media (max-width: 720px) {
  .track { padding: 26px 14px 48px; }
  .track__media { grid-template-columns: 1fr; }
  .qr-card { justify-items: center; }
  .track__title { font-size: 1.6rem; }
}

/* ================================================= modal media controls === */

.dropzone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 5.5rem;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.dropzone:hover,
.dropzone.is-dragging { border-color: var(--teal); background: #eef2f1; }
.dropzone:focus-within { outline: 2px solid var(--teal); outline-offset: 2px; }
.dropzone__preview { max-height: 9rem; max-width: 100%; border-radius: 6px; display: block; }

#photo-remove { display: inline-block; margin-top: 8px; padding-left: 0; }

.qr-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
}
.qr-preview__img { width: 72px; height: 72px; flex: none; image-rendering: pixelated; }
.qr-preview__text { margin: 0; font-size: .8rem; color: var(--muted); line-height: 1.45; }
.qr-preview__text code { font-family: var(--mono); color: var(--ink-soft); word-break: break-all; }
