:root {
  --bg: #f4f8f6;
  --bg-soft: #edf5f1;
  --text: #101827;
  --muted: #4b5f5b;
  --card: #ffffff;
  --border: #cbd8d2;
  --focus: #ffbf47;
  --primary: #06412f;
  --primary-2: #0c6b4d;
  --primary-hover: #043225;
  --accent: #b7791f;
  --accent-soft: #fff7e6;
  --success-bg: #e8f7ef;
  --success-border: #137333;
  --error-bg: #fff0f0;
  --error-border: #b00020;
  --shadow: 0 10px 24px rgba(16, 24, 39, 0.08);
  --radius: 1rem;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(12, 107, 77, 0.14), transparent 18rem),
    linear-gradient(180deg, #f8fbf9 0%, var(--bg) 45%, #eef5f1 100%);
  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.85rem, 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));
  z-index: 50;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: var(--focus);
  color: #000;
  font-weight: 900;
  transform: translateY(-160%);
}

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

.site-header {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ffffff 0%, #f2faf5 55%, #fff8e8 100%);
  border-bottom: 1px solid var(--border);
  padding: calc(0.42rem + env(safe-area-inset-top)) 0 0.5rem;
  box-shadow: 0 4px 14px rgba(16, 24, 39, 0.06);
}

.site-header::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 0.34rem;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-2) 55%, var(--accent) 100%);
}

.site-header::after {
  content: "";
  position: absolute;
  right: -4rem;
  top: -5rem;
  width: 12rem;
  height: 12rem;
  border-radius: 50%;
  background: rgba(183, 121, 31, 0.12);
  pointer-events: none;
}

.logo-left-title-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  min-height: 4.35rem;
  padding-top: 0.22rem;
}

.brand-main-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.64rem;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-logo {
  display: block;
  flex: 0 0 auto;
  width: clamp(3.7rem, 15vw, 5.3rem);
  height: auto;
  filter: drop-shadow(0 4px 8px rgba(16, 24, 39, 0.15));
}

.brand-title-stack {
  display: grid;
  gap: 0.06rem;
  min-width: 0;
}

.app-name-inline {
  margin: 0;
  color: var(--primary);
  font-size: clamp(1.42rem, 5.5vw, 2.18rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.logo-left-title-header h1 {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.82rem, 3vw, 1.02rem);
  font-weight: 500;
  line-height: 1.12;
  white-space: nowrap;
}

.login-button-compact {
  flex: 0 0 auto;
  align-self: center;
  width: auto;
  min-height: 1.65rem;
  padding: 0.22rem 0.52rem;
  border-width: 1px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(16, 24, 39, 0.08);
}

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

h1 {
  font-size: clamp(1.22rem, 5.2vw, 1.9rem);
}

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

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.card,
.admin-panel {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0.7rem 0;
  padding: 0.9rem;
  box-shadow: var(--shadow);
}

.accent-card::before,
.admin-card::before,
.admin-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 0.28rem;
  background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--accent));
}

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

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

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

.lookup-field {
  display: grid;
  gap: 0.42rem;
}

.lookup-input-row {
  align-items: end;
}

label,
legend {
  color: var(--text);
  font-weight: 850;
}

input[type="text"],
input[type="password"],
input[type="file"] {
  width: 100%;
  min-height: 3.35rem;
  border: 2px solid #566963;
  border-radius: 0.85rem;
  padding: 0.86rem 0.95rem;
  background: #fff;
  color: var(--text);
  font-size: 1.06rem;
}

input[type="file"] {
  padding-top: 0.72rem;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 3.35rem;
  border: 2px solid var(--primary);
  border-radius: 0.85rem;
  padding: 0.82rem 1rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 10px rgba(6, 65, 47, 0.18);
}

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

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

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

.camera-control::before,
.find-button::before,
.scan-again-button::before,
.home-button::before,
.location-link::before {
  display: inline-block;
  margin-right: 0.45rem;
  font-weight: 900;
}

.camera-control::before { content: "◈"; }
.find-button::before { content: "⌕"; }
.scan-again-button::before { content: "↻"; }
.home-button::before { content: "⌂"; }
.location-link::before { content: "⌖"; }

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

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

.status,
.notice {
  margin: 0;
  border: 1px solid var(--border);
  border-left: 0.42rem solid var(--primary-2);
  border-radius: 0.85rem;
  padding: 0.78rem 0.9rem;
  background: #f8fcfa;
  color: var(--text);
  font-weight: 800;
}

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

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

.scanner-panel {
  position: relative;
  width: 100%;
  min-height: min(70dvh, 34rem);
  overflow: hidden;
  border: 3px solid var(--primary);
  border-radius: 1.15rem;
  background: #000;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.22), var(--shadow);
}

.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.96);
  border-radius: 1.2rem;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.24), 0 0 0 0.55rem rgba(255, 191, 71, 0.18);
}

.result h2 {
  color: var(--primary);
  font-size: 1.18rem;
}

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

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

caption {
  margin-bottom: 0.55rem;
  color: var(--primary);
  font-weight: 900;
  text-align: left;
}

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

th {
  width: 36%;
  color: #18352b;
  background: #eef8f3;
  font-weight: 900;
}

td {
  background: #fff;
}

tr:first-child th {
  border-top-left-radius: 0.8rem;
}

tr:first-child td {
  border-top-right-radius: 0.8rem;
}

tr:last-child th {
  border-bottom-left-radius: 0.8rem;
}

tr:last-child td {
  border-bottom-right-radius: 0.8rem;
}

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

.footer-stamp {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0.55rem auto 0;
  padding: 0.48rem 0.78rem;
  border: 1px solid rgba(6, 65, 47, 0.35);
  border-radius: 999px;
  color: var(--primary);
  background: rgba(255, 255, 255, 0.88);
  font-size: 0.88rem;
  font-weight: 850;
  text-align: center;
}

.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;
}

/* Admin */
.admin-page {
  background:
    radial-gradient(circle at top left, rgba(6, 65, 47, 0.16), transparent 18rem),
    linear-gradient(180deg, #f9fcfa 0%, #eef5f1 100%);
}

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

.admin-header {
  padding: calc(0.5rem + env(safe-area-inset-top)) 0 0.55rem;
}

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

.admin-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.admin-logo {
  width: 2.8rem;
  height: auto;
  flex: 0 0 auto;
  filter: drop-shadow(0 3px 6px rgba(16, 24, 39, 0.15));
}

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

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

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

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

.admin-panel {
  padding: 0.9rem;
}

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

.metric {
  min-width: 0;
  border: 1px solid #cbd8d2;
  border-radius: 0.9rem;
  padding: 0.72rem;
  background: linear-gradient(180deg, #ffffff, #f3faf6);
}

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

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

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

.admin-card {
  margin: 0;
  padding: 0.9rem;
}

.section-title-row h2 {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.section-title-row h2::before,
#dashboard-heading::before,
#login-heading::before {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.6rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-size: 0.95rem;
  line-height: 1;
}

#import-heading::before { content: "↥"; }
#password-heading::before { content: "●"; }
#dashboard-heading::before { content: "✓"; margin-right: 0.45rem; }
#login-heading::before { content: "●"; margin-right: 0.45rem; }

.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.95rem;
  border-width: 1px;
  border-color: #64766f;
  border-radius: 0.72rem;
  padding: 0.72rem 0.78rem;
  font-size: 1rem;
}

.admin-page .button,
.admin-page button {
  min-height: 2.95rem;
  border-radius: 0.72rem;
  padding: 0.72rem 0.95rem;
}

.mode-fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.48rem;
  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.4rem;
  min-height: 2.65rem;
  padding: 0.58rem 0.68rem;
  border: 1px solid #cbd8d2;
  border-radius: 0.72rem;
  background: #f7fbf9;
  color: var(--text);
  font-weight: 850;
}

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

/* Location QR */
.muted-text {
  color: var(--muted);
}

.location-qr-card {
  display: grid;
  justify-items: start;
  gap: 0.58rem;
}

.qr-target {
  width: min(52vw, 11rem);
  max-width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.82rem;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 24, 39, 0.08);
}

.qr-target svg {
  display: block;
  width: 100%;
  height: auto;
}

.location-link {
  min-height: 2.4rem;
  padding: 0.52rem 0.78rem;
  border-radius: 0.65rem;
  font-size: 0.92rem;
}

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

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

  .button,
  button {
    width: auto;
  }
}

@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) {
  .wrap {
    width: min(100% - 0.7rem, 44rem);
  }

  .logo-left-title-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 3.75rem;
    gap: 0.38rem;
    padding-top: 0.42rem;
  }

  .brand-main-row {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    justify-content: flex-start;
    gap: 0.44rem;
  }

  .brand-logo {
    width: clamp(2.85rem, 13vw, 3.65rem);
  }

  .brand-title-stack {
    min-width: 0;
    max-width: none;
  }

  .app-name-inline {
    font-size: clamp(1.02rem, 5vw, 1.42rem);
    line-height: 1.03;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .logo-left-title-header h1 {
    font-size: clamp(0.66rem, 2.85vw, 0.82rem);
    line-height: 1.16;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .login-button-compact {
    flex: 0 0 auto;
    align-self: center;
    width: auto;
    min-height: 1.55rem;
    padding: 0.18rem 0.45rem;
    font-size: 0.62rem;
    margin: 0;
  }

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

  tr {
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    overflow: hidden;
    margin-bottom: 0.7rem;
    background: #fff;
  }

  th,
  td {
    border: 0;
  }

  th {
    padding-bottom: 0.3rem;
  }

  td {
    padding-top: 0.3rem;
  }

  .location-qr-card {
    justify-items: center;
  }

  .qr-target {
    width: min(68vw, 12rem);
  }
}

@media (max-width: 24rem) {
  .logo-left-title-header {
    gap: 0.28rem;
  }

  .brand-logo {
    width: 2.55rem;
  }

  .brand-main-row {
    gap: 0.28rem;
  }

  .brand-title-stack {
    max-width: none;
  }

  .app-name-inline {
    font-size: clamp(0.86rem, 5vw, 1.02rem);
  }

  .logo-left-title-header h1 {
    font-size: 0.56rem;
  }

  .login-button-compact {
    min-height: 1.42rem;
    padding-inline: 0.34rem;
    font-size: 0.56rem;
  }

  .small-button {
    padding-left: 0.64rem;
    padding-right: 0.64rem;
  }

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

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

/* Public user login and registration */
.inline-form {
  display: inline-flex;
  margin: 0;
}

.auth-card {
  max-width: 30rem;
  margin: 1rem auto;
  padding: 1rem;
}

.auth-card h2 {
  color: var(--primary);
  font-size: clamp(1.2rem, 5vw, 1.55rem);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.42rem;
  margin: 0.75rem 0;
}

.auth-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f7fbf9;
  color: var(--primary);
  font-weight: 900;
  text-decoration: none;
}

.auth-tab.active {
  border-color: var(--primary);
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
}

.auth-form {
  margin-top: 0.6rem;
}

.resend-form {
  margin-top: 0.65rem;
}

.user-chip {
  width: fit-content;
  max-width: 100%;
  margin: 0.65rem 0 0;
  border: 1px solid rgba(6, 65, 47, 0.25);
  border-radius: 999px;
  padding: 0.42rem 0.68rem;
  background: #ffffff;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 750;
  box-shadow: 0 4px 10px rgba(16, 24, 39, 0.06);
}

input[type="email"],
input[type="tel"] {
  width: 100%;
  min-height: 3.35rem;
  border: 2px solid #566963;
  border-radius: 0.85rem;
  padding: 0.86rem 0.95rem;
  background: #fff;
  color: var(--text);
  font-size: 1.06rem;
}

.compact-form input[type="email"],
.compact-form input[type="tel"] {
  min-height: 2.95rem;
  border-width: 1px;
  border-color: #64766f;
  border-radius: 0.72rem;
  padding: 0.72rem 0.78rem;
  font-size: 1rem;
}

@media (max-width: 37.99rem) {
  .auth-card {
    margin-top: 0.75rem;
  }

  .auth-tabs {
    gap: 0.32rem;
  }

  .auth-tab {
    min-height: 2.35rem;
    font-size: 0.9rem;
  }

  .inline-form .login-button-compact {
    min-height: 1.55rem;
  }
}

/* Password visibility and quick rescan */
.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0.5rem;
}

.password-field input[type="password"],
.password-field input[type="text"] {
  min-width: 0;
}

.password-toggle,
.compact-form .password-toggle,
.admin-page .password-toggle {
  width: auto;
  min-width: 4.7rem;
  min-height: 2.95rem;
  border-color: #64766f;
  background: #ffffff;
  color: var(--primary);
  box-shadow: none;
  padding: 0.55rem 0.78rem;
  white-space: nowrap;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: #e9f5ef;
  color: var(--primary-hover);
}

.result-actions {
  display: flex;
  justify-content: center;
  margin: 0.7rem 0;
}

.new-scan-button,
.scan-again-button {
  width: auto;
  min-width: 9rem;
}

.new-scan-button::before {
  content: "↻";
  display: inline-block;
  margin-right: 0.45rem;
  font-weight: 900;
}

@media (max-width: 25rem) {
  .password-field {
    gap: 0.38rem;
  }

  .password-toggle,
  .compact-form .password-toggle,
  .admin-page .password-toggle {
    min-width: 4rem;
    padding-left: 0.58rem;
    padding-right: 0.58rem;
  }

  .new-scan-button,
  .scan-again-button {
    width: 100%;
  }
}

/* Large Excel import progress */
.import-progress {
  display: grid;
  gap: 0.42rem;
  border: 1px solid rgba(6, 65, 47, 0.22);
  border-radius: 0.82rem;
  padding: 0.72rem;
  background: #f7fbf9;
}

.import-progress[hidden] {
  display: none;
}

.import-progress label {
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 900;
}

.import-progress progress {
  width: 100%;
  height: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: #ffffff;
}

.import-progress progress::-webkit-progress-bar {
  background: #ffffff;
  border-radius: 999px;
}

.import-progress progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--accent));
  border-radius: 999px;
}

.import-progress progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--accent));
  border-radius: 999px;
}

.import-progress p {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 800;
}

button:disabled,
.button:disabled,
input:disabled {
  opacity: 0.68;
  cursor: not-allowed;
}


/* Final location QR display */
.location-qr-maktab {
  margin: 0;
  padding: 0.36rem 0.58rem;
  border: 1px solid rgba(6, 65, 47, 0.18);
  border-radius: 999px;
  background: #eef8f4;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 850;
}

.location-qr-maktab strong {
  font-weight: 950;
}

.lookup-search-form {
  display: grid;
  gap: 0.75rem;
}

.lookup-help {
  margin: 0;
  color: var(--muted);
  font-weight: 850;
}

.lookup-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  width: 100%;
}

.lookup-field,
.passport-lookup-field {
  display: grid !important;
  gap: 0.42rem;
  min-width: 0;
}

.lookup-find-button {
  width: 100%;
}

@media (min-width: 48rem) {
  .lookup-fields {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .lookup-find-button {
    justify-self: start;
    width: auto;
    min-width: 9rem;
  }
}
