:root {
  --bg: #f4f6f8;
  --text: #111111;
  --muted: #4a4a4a;
  --card: #ffffff;
  --border: #c6cbd1;
  --focus: #ffbf47;
  --primary: #003f8c;
  --primary-hover: #002f69;
  --success-bg: #e9f7ef;
  --success-border: #1e7e34;
  --error-bg: #fff0f0;
  --error-border: #b00020;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

.wrap {
  width: min(100% - 0.75rem, 44rem);
  margin: 0 auto;
}

.skip-link {
  position: absolute;
  top: calc(0.5rem + env(safe-area-inset-top));
  left: calc(0.5rem + env(safe-area-inset-left));
  padding: 0.75rem 1rem;
  background: var(--focus);
  color: #000;
  transform: translateY(-150%);
  z-index: 20;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: calc(0.65rem + env(safe-area-inset-top)) 0 0.65rem;
}

.compact-header {
  display: grid;
  gap: 0.15rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.top-bar > div {
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

h1,
h2 {
  line-height: 1.15;
  margin: 0;
}

h1 {
  font-size: clamp(1.2rem, 5.5vw, 1.9rem);
}

h2 {
  font-size: clamp(1.1rem, 5vw, 1.45rem);
}

.hint,
.footer {
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  margin: 0.65rem 0;
  padding: 0.85rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.scanner-card {
  display: grid;
  gap: 0.8rem;
}

.lookup-form,
.actions {
  display: grid;
  gap: 0.65rem;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

label,
legend {
  font-weight: 800;
}

input[type="text"],
input[type="password"],
input[type="file"] {
  width: 100%;
  min-height: 3.45rem;
  border: 2px solid var(--muted);
  border-radius: 0.8rem;
  padding: 0.9rem;
  background: #fff;
  color: var(--text);
  font-size: 1.08rem;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 3.45rem;
  border: 2px solid var(--primary);
  border-radius: 0.8rem;
  padding: 0.9rem 1rem;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover,
.button:hover {
  background: var(--primary-hover);
}

.secondary {
  background: #ffffff;
  color: var(--primary);
}

.secondary:hover {
  background: #eef4ff;
}

.small-button {
  width: auto;
  min-height: 2.75rem;
  padding: 0.65rem 0.85rem;
  white-space: nowrap;
}

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.status,
.notice {
  margin: 0;
  border-left: 0.4rem solid var(--border);
  border-radius: 0.7rem;
  padding: 0.8rem 0.9rem;
  background: #f2f2f2;
  font-weight: 700;
}

.success {
  border-color: var(--success-border);
  background: var(--success-bg);
}

.error {
  border-color: var(--error-border);
  background: var(--error-bg);
}

.scanner-panel {
  position: relative;
  width: 100%;
  min-height: min(70dvh, 34rem);
  overflow: hidden;
  border: 2px solid var(--text);
  border-radius: 1rem;
  background: #000;
}

.preview {
  display: block;
  width: 100%;
  height: min(70dvh, 34rem);
  object-fit: cover;
  background: #000;
}

.scan-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(72vw, 18rem);
  aspect-ratio: 1;
  border: 0.25rem solid rgba(255, 255, 255, 0.94);
  border-radius: 1rem;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.2);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

caption {
  text-align: left;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

th,
td {
  border: 1px solid var(--border);
  padding: 0.75rem;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  width: 36%;
  background: #f2f2f2;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.75rem;
}

.admin-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.stats-grid p {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.75rem;
  background: #f8f8f8;
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid span {
  margin-top: 0.15rem;
  font-size: 1.15rem;
  font-weight: 800;
}

.radio {
  display: block;
  font-weight: 400;
  margin-top: 0.5rem;
}

.footer {
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.footer-stamp {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0.5rem auto 0;
  padding: 0.45rem 0.7rem;
  border: 2px solid var(--primary);
  border-radius: 999px;
  color: var(--primary);
  background: #ffffff;
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
}

@media (min-width: 38rem) {
  .input-row {
    grid-template-columns: 1fr auto;
  }

  .button,
  button {
    width: auto;
  }

  .actions {
    grid-template-columns: max-content max-content;
  }
}

@media (max-width: 37.99rem) {
  .top-bar {
    align-items: flex-start;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  table,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  tr {
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
    margin-bottom: 0.65rem;
  }

  th,
  td {
    border: 0;
  }

  th {
    padding-bottom: 0.25rem;
  }

  td {
    padding-top: 0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

/* Compact UI update */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.scanner-card {
  gap: 0.65rem;
}

.status {
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
}

.result h2 {
  font-size: 1.15rem;
}

.admin-page {
  background: #eef2f7;
}

.admin-page .wrap {
  width: min(100% - 1rem, 58rem);
}

.admin-header {
  padding: calc(0.5rem + env(safe-area-inset-top)) 0 0.5rem;
  border-bottom-color: #d7dde6;
}

.admin-top-bar h1 {
  font-size: clamp(1.15rem, 4.6vw, 1.65rem);
}

.admin-wrap {
  padding-top: 0.55rem;
}

.admin-login-card {
  max-width: 28rem;
  margin: 1rem auto;
  padding: 1rem;
}

.admin-login-card h2,
.admin-card h2,
.admin-panel h2 {
  font-size: 1.1rem;
}

.admin-panel {
  margin: 0.65rem 0;
  padding: 0.85rem;
  border: 1px solid #d7dde6;
  border-radius: 1rem;
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.06);
}

.dashboard-head,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.dashboard-head {
  margin-bottom: 0.75rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.metric {
  min-width: 0;
  border: 1px solid #dde3ec;
  border-radius: 0.85rem;
  padding: 0.7rem;
  background: #f8fafc;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric strong {
  display: block;
  margin-top: 0.15rem;
  font-size: clamp(1.15rem, 4vw, 1.55rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.admin-card {
  margin: 0;
  padding: 0.85rem;
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.05);
}

.compact-form {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.65rem;
}

.compact-form label,
.compact-form legend {
  font-size: 0.92rem;
}

.compact-form input[type="text"],
.compact-form input[type="password"],
.compact-form input[type="file"] {
  min-height: 2.9rem;
  border-width: 1px;
  border-color: #7a8594;
  border-radius: 0.65rem;
  padding: 0.7rem 0.75rem;
  font-size: 1rem;
}

.admin-page .button,
.admin-page button {
  min-height: 2.9rem;
  border-radius: 0.65rem;
  padding: 0.7rem 0.9rem;
}

.mode-fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  border: 0;
  padding: 0;
  margin: 0;
}

.mode-fieldset legend {
  grid-column: 1 / -1;
  margin-bottom: 0.1rem;
}

.radio-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.55rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.65rem;
  background: #f8fafc;
  font-weight: 800;
}

.radio-pill input {
  width: 1.05rem;
  height: 1.05rem;
}

.admin-page .notice {
  margin: 0.65rem 0;
}

@media (max-width: 48rem) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 37.99rem) {
  .admin-top-bar {
    align-items: center;
  }

  .dashboard-head {
    align-items: flex-start;
  }

  .mode-fieldset {
    grid-template-columns: 1fr;
  }
}
