:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d9dee7;
  --brand: #0f8a4b;
  --brand-dark: #0b6f3d;
  --accent: #ffd31a;
  --ok: #0f8a4b;
  --warn: #b7791f;
  --bad: #b42318;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Arial, Helvetica, sans-serif;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 64px;
  padding: 12px clamp(16px, 4vw, 40px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar strong {
  display: block;
  font-size: 18px;
}

.topbar span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  position: relative;
}

.topbar nav a,
.admin-menu-toggle {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.topbar nav a.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 700;
}

.admin-menu {
  display: flex;
  gap: 8px;
}

.admin-menu-toggle {
  display: none;
  min-height: auto;
}

.container {
  margin: 0 auto;
  max-width: 1180px;
  padding: 24px clamp(16px, 4vw, 40px) 48px;
}

.install-notice {
  align-items: center;
  background: #eaf2ff;
  border: 1px solid #8bb8ff;
  border-radius: 8px;
  bottom: 12px;
  box-shadow: 0 12px 30px rgba(29, 78, 216, 0.18);
  color: #fff;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  left: 50%;
  max-width: min(440px, calc(100vw - 20px));
  padding: 10px;
  position: fixed;
  transform: translateX(-50%);
  width: 100%;
  z-index: 120;
}

.install-notice[hidden] {
  display: none;
}

.install-notice strong,
.install-notice span {
  display: block;
}

.install-notice strong {
  color: #123b7a;
  font-size: 14px;
}

.install-notice span {
  color: #42628f;
  font-size: 12px;
}

.install-action,
.install-close {
  min-height: 34px;
}

.install-action {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 7px 11px;
}

.install-close {
  align-items: center;
  background: transparent;
  border-color: #b8cff5;
  color: #123b7a;
  display: inline-flex;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  padding: 0;
  width: 34px;
}

.page-head {
  margin-bottom: 20px;
}

.page-head-actions {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.1;
  margin-bottom: 8px;
}

h2 {
  font-size: 20px;
}

button,
input,
select {
  font: inherit;
}

button,
.button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  padding: 10px 14px;
}

button.primary,
.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

button.primary:hover,
.primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

input,
select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 44px;
  padding: 10px 12px;
  width: 100%;
}

.auth-panel,
.panel,
.ticket-card,
.scanner-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.auth-panel {
  margin: 40px auto;
  max-width: 420px;
}

.stack {
  display: grid;
  gap: 14px;
}

.metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metrics article {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 6px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
}

.metrics span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.metrics strong {
  display: block;
  font-size: 30px;
  line-height: 1.1;
}

.grid-2 {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.line {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 0;
  padding: 10px 0;
}

.scan-log-item {
  align-items: center;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px 0;
}

.scan-log-item div {
  min-width: 0;
}

.scan-log-item strong,
.scan-log-item span,
.scan-log-item time {
  display: block;
  overflow-wrap: anywhere;
}

.scan-log-item span,
.scan-log-item time {
  color: var(--muted);
  font-size: 13px;
}

.scan-log-item div:last-child {
  text-align: right;
}

.log-result {
  color: var(--ink) !important;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-log-item,
.user-row {
  align-items: center;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1.4fr) minmax(120px, 0.7fr) minmax(150px, 0.9fr);
  padding: 12px 0;
}

.user-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.admin-log-item div,
.user-row div {
  min-width: 0;
}

.admin-log-item strong,
.admin-log-item span,
.admin-log-item time,
.user-row strong,
.user-row span {
  display: block;
  overflow-wrap: anywhere;
}

.admin-log-item span,
.admin-log-item time,
.user-row span {
  color: var(--muted);
  font-size: 13px;
}

.user-row div:last-child {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.pagination {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: center;
  padding-top: 16px;
}

.pagination a,
.pagination span,
.user-row a {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.pagination a {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.search-box,
.manual-row,
.scanner-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.search-box input,
.manual-row input {
  flex: 1;
}

.toggle {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-flex;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
}

.toggle input {
  min-height: auto;
  width: auto;
}

#scannerVideo {
  aspect-ratio: 4 / 3;
  background: #111827;
  border-radius: var(--radius);
  display: block;
  margin-bottom: 14px;
  max-height: 62vh;
  object-fit: cover;
  width: 100%;
}

.scan-result {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.result-banner {
  border-radius: 6px;
  font-size: clamp(18px, 4vw, 28px);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.15;
  margin-bottom: 12px;
  padding: 14px;
  text-align: center;
}

.banner-ok {
  background: #12b76a;
  color: #fff;
}

.banner-warn {
  background: #fdb022;
  color: #1f2933;
}

.banner-bad {
  background: #d92d20;
  color: #fff;
}

.scan-result.ok {
  border-color: var(--ok);
  background: #ecfdf3;
}

.scan-result.bad {
  border-color: var(--bad);
  background: #fff1f0;
}

.ticket-card {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.ticket-card h3 {
  margin-bottom: 2px;
}

.ticket-card dl {
  display: grid;
  gap: 8px 14px;
  grid-template-columns: 120px minmax(0, 1fr);
  margin: 0;
}

.ticket-card dt {
  color: var(--muted);
  font-weight: 700;
}

.ticket-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.modal {
  display: none;
}

.modal.open {
  align-items: center;
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 16px;
  position: fixed;
  z-index: 100;
}

.modal-backdrop {
  background: rgba(15, 23, 42, 0.72);
  inset: 0;
  position: absolute;
}

.modal-panel {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.35);
  max-height: calc(100vh - 32px);
  max-width: 620px;
  overflow: auto;
  padding: 18px;
  position: relative;
  width: min(620px, 100%);
}

.modal-close {
  align-items: center;
  background: #111827;
  border-color: #111827;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  font-weight: 800;
  height: 40px;
  justify-content: center;
  min-height: 40px;
  padding: 0;
  position: absolute;
  right: 12px;
  top: 12px;
  width: 40px;
}

#modalBody {
  padding-top: 42px;
}

#modalBody .ticket-card {
  border: 0;
  padding: 0;
}

.modal-body-form {
  padding-top: 36px;
}

.status {
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  justify-self: start;
  padding: 4px 9px;
  text-transform: uppercase;
}

.status-unused {
  background: #eef4ff;
  color: #1d4ed8;
}

.status-checked_in {
  background: #ecfdf3;
  color: var(--ok);
}

.status-void {
  background: #fff1f0;
  color: var(--bad);
}

.alert {
  background: #fff8db;
  border: 1px solid #f2d06b;
  border-radius: var(--radius);
  margin-bottom: 14px;
  padding: 12px;
}

.alert.danger {
  background: #fff1f0;
  border-color: #fda29b;
}

.alert.success {
  background: #ecfdf3;
  border-color: #75e0a7;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar nav {
    width: 100%;
  }

  .admin-menu-toggle {
    background: #fff;
    display: inline-flex;
  }

  .admin-menu {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
    display: none;
    flex-direction: column;
    left: 0;
    padding: 8px;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 30;
  }

  .admin-menu.open {
    display: flex;
  }

  .admin-menu a {
    display: block;
    width: 100%;
  }

  .page-head-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .install-notice {
    align-items: stretch;
    bottom: 10px;
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .metrics,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .scanner-toolbar,
  .search-box,
  .manual-row {
    flex-direction: column;
  }

  .ticket-card dl {
    grid-template-columns: 1fr;
  }

  .scan-log-item {
    grid-template-columns: 1fr;
  }

  .scan-log-item div:last-child {
    text-align: left;
  }

  .admin-log-item,
  .user-row,
  .users-layout {
    grid-template-columns: 1fr;
  }

  .user-row div:last-child {
    justify-content: flex-start;
  }

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination a,
  .pagination span {
    text-align: center;
  }
}
