:root {
  --bg: #071516;
  --panel: #0d2224;
  --panel2: #102b2e;
  --text: #e9ffff;
  --muted: #98b9bc;
  --mint: #13d0bd;
  --mint2: #0fa99a;
  --danger: #ff6b6b;
  --line: rgba(255,255,255,.12);
  --shadow: 0 18px 50px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(19,208,189,.14), transparent 35%),
    radial-gradient(circle at 80% 20%, rgba(45,128,255,.09), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input, select {
  font: inherit;
}

.page {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 18px;
  padding-bottom: 42px;
}

.landing-card {
  min-height: 88vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 26px;
}

.logo {
  width: min(340px, 86vw);
  height: auto;
  display: block;
}

.access-form {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
}

.big-input,
.big-select,
.admin-grid input,
.admin-inline input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.06);
  color: var(--text);
  padding: 12px 16px;
  outline: none;
}

.big-input:focus,
.big-select:focus,
.admin-grid input:focus,
.admin-inline input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 4px rgba(19,208,189,.12);
}

.primary-btn,
.scan-btn,
.secondary-btn,
.copy-btn,
.danger-btn {
  border: 0;
  border-radius: 16px;
  min-height: 52px;
  padding: 12px 16px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.primary-btn,
.scan-btn {
  background: linear-gradient(135deg, var(--mint), var(--mint2));
  color: #031413;
  font-size: 1.1rem;
}

.scan-btn {
  width: 100%;
  min-height: 72px;
  margin-top: 18px;
  font-size: clamp(1.15rem, 4vw, 1.55rem);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.secondary-btn,
.copy-btn {
  background: rgba(255,255,255,.09);
  border: 1px solid var(--line);
  color: var(--text);
}

.danger-btn {
  background: rgba(255,107,107,.12);
  border: 1px solid rgba(255,107,107,.35);
  color: #ffd7d7;
}

.error-box {
  background: rgba(255,107,107,.13);
  border: 1px solid rgba(255,107,107,.34);
  color: #ffdada;
  padding: 12px 14px;
  border-radius: 14px;
  text-align: center;
  font-weight: 700;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 8px 0 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: .85rem;
}

.who {
  font-size: clamp(1.35rem, 6vw, 2rem);
  font-weight: 900;
}

.small-link {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  padding: 10px 14px;
  white-space: nowrap;
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.035));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 18px;
  margin: 16px 0;
  box-shadow: var(--shadow);
}

.label {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 700;
}

.section-head,
.button-row,
.filter-line {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

h2 {
  margin: 0 0 14px;
  font-size: 1.25rem;
}

.section-head h2 {
  margin: 0;
}

.scanner-wrap {
  margin-top: 16px;
}

.scanner-video {
  width: 100%;
  max-height: 58vh;
  object-fit: cover;
  border-radius: 18px;
  background: #000;
  border: 1px solid var(--line);
}

.scan-status {
  margin-top: 10px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.scan-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.scan-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px;
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.scan-time {
  color: var(--muted);
  font-weight: 800;
}

.scan-code {
  font-size: clamp(1.05rem, 5vw, 1.35rem);
  font-weight: 950;
  word-break: break-word;
}

.scan-meta {
  color: var(--muted);
  margin-top: 2px;
}

.muted {
  color: var(--muted);
}

.bottom-nav {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

.bottom-nav a {
  color: var(--text);
  text-decoration: none;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.06);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.movement-grid {
  grid-template-columns: minmax(220px, 2fr) 100px 120px 130px 130px;
}

.scan-admin-grid {
  grid-template-columns: minmax(160px, 1.5fr) minmax(160px, 1.5fr) minmax(140px, 1fr) 130px 100px 100px;
}

.admin-inline {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
}

.admin-date {
  color: var(--muted);
  font-size: .95rem;
}

.hidden {
  display: none !important;
}

@media (min-width: 760px) {
  .page { padding: 28px; }
  .card { padding: 24px; }
}

@media (max-width: 620px) {
  .page { padding: 14px; }
  .topbar { align-items: flex-start; }
  .card { border-radius: 20px; padding: 14px; }
  .scan-row { grid-template-columns: 1fr; gap: 2px; }
  .scan-time { font-size: .95rem; }
  .filter-line .big-select,
  .filter-line .secondary-btn {
    width: 100%;
  }
}

/* Scanner header tidy-up */
.app-header {
  align-items: center;
}

.brand-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.mini-logo {
  display: block;
  width: min(170px, 38vw);
  height: auto;
}

.user-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.signed-in {
  text-align: right;
  min-width: 0;
}

.small-who {
  font-size: clamp(1rem, 4vw, 1.25rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 520px) {
  .mini-logo {
    width: min(135px, 34vw);
  }

  .user-right {
    gap: 8px;
  }

  .signed-in .eyebrow {
    font-size: .72rem;
  }

  .small-who {
    font-size: .95rem;
    max-width: 110px;
  }
}

/* Scan success feedback */
.scan-success::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: rgba(19, 208, 189, 0.28);
  animation: scanFlash 180ms ease-out;
}

@keyframes scanFlash {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Stronger scan success feedback */
.scan-success {
  animation: scanBodyPop 260ms ease-out;
}

.scan-success::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99999;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.95), rgba(19,208,189,0.75) 38%, rgba(19,208,189,0.25) 72%);
  animation: scanFlashStrong 260ms ease-out;
}

@keyframes scanFlashStrong {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes scanBodyPop {
  0% { filter: brightness(1.6); }
  100% { filter: brightness(1); }
}

/* Very obvious scan success feedback */
.scan-success {
  animation: scanBodyPopHuge 420ms ease-out;
}

.scan-success::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999999;
  background: rgba(255, 255, 255, 0.92);
  animation: scanFlashHuge 420ms ease-out;
}

.scan-success::after {
  content: "✓";
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 1000000;
  font-size: min(42vw, 180px);
  font-weight: 1000;
  color: #031413;
  text-shadow: 0 0 28px rgba(19,208,189,.95);
  animation: scanTickHuge 420ms ease-out;
}

@keyframes scanFlashHuge {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes scanTickHuge {
  0% { opacity: 0; transform: scale(.65); }
  20% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 0; transform: scale(1.25); }
}

@keyframes scanBodyPopHuge {
  0% { filter: brightness(2.1) saturate(1.6); }
  100% { filter: brightness(1) saturate(1); }
}

/* Longer flash duration (slower fade) */
.scan-success {
  animation: scanBodyPopHuge 800ms ease-out;
}

.scan-success::before {
  animation: scanFlashHuge 800ms ease-out;
}

.scan-success::after {
  animation: scanTickHuge 800ms ease-out;
}


/* Grouped scan list layout */
.scan-group {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.scan-group + .scan-group {
  margin-top: 24px;
}

.scan-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.scan-group-head h3 {
  margin: 0;
  font-size: clamp(1.15rem, 5vw, 1.55rem);
  font-weight: 950;
  color: var(--text);
}

.small-copy-btn {
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: .9rem;
  white-space: nowrap;
}

.scan-group-list {
  display: grid;
  gap: 2px;
}

.scan-line-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.scan-line-row .scan-code {
  font-size: clamp(1.05rem, 4.8vw, 1.4rem);
  font-weight: 950;
  line-height: 1.15;
  word-break: break-word;
}

.scan-line-meta {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: baseline;
  color: var(--muted);
  font-weight: 750;
  font-size: clamp(.82rem, 3.5vw, .98rem);
  white-space: nowrap;
}

@media (max-width: 430px) {
  .scan-line-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .scan-line-meta {
    gap: 5px;
    font-size: .82rem;
  }
}

/* Grouped history copy buttons */
.movement-group {
  margin-top: 24px;
}

.movement-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 6px;
}

.movement-head h2 {
  margin: 0;
}

.copy-group-btn {
  min-height: 42px;
  padding: 8px 12px;
  white-space: nowrap;
}

.scan-main-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
}

.inline-meta {
  white-space: nowrap;
  text-align: right;
  font-weight: 700;
}

@media (max-width: 520px) {
  .movement-head {
    align-items: flex-start;
  }

  .scan-main-line {
    align-items: flex-start;
  }

  .inline-meta {
    font-size: .85rem;
  }
}

/* Clean grouped history rows */
.movement-group .scan-list {
  gap: 0;
  margin-top: 6px;
}

.history-scan-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.history-scan-code {
  min-width: 0;
  font-size: clamp(1rem, 4.5vw, 1.25rem);
  font-weight: 950;
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: normal;
}

.history-scan-meta {
  white-space: nowrap;
  color: var(--muted);
  font-size: .95rem;
  font-weight: 800;
  text-align: right;
}

@media (max-width: 520px) {
  .history-scan-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 9px 0;
  }

  .history-scan-code {
    font-size: 1.05rem;
  }

  .history-scan-meta {
    font-size: .82rem;
  }
}

/* History action layout tidy-up */
.history-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  margin-bottom: 20px;
}

.history-filter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.history-filter .big-select,
.history-filter .secondary-btn,
.download-csv-btn {
  min-height: 52px;
}

.download-csv-btn {
  white-space: nowrap;
}

@media (max-width: 620px) {
  .history-actions {
    grid-template-columns: 1fr;
  }

  .history-filter {
    grid-template-columns: 1fr auto;
  }

  .download-csv-btn {
    width: 100%;
  }
}

/* Auto-filter history dropdown */
.history-filter {
  grid-template-columns: minmax(0, 1fr);
}

.history-filter .big-select {
  width: 100%;
}
