/* =========================================================================
   UDI Secure — Design System
   ========================================================================= */

:root {
  /* Brand */
  --brand-500: #d100c9;
  --brand-600: #b0019f;
  --brand-700: #880486;
  --accent-500: #6d28d9;
  --brand-gradient: linear-gradient(135deg, #d100c9 0%, #7c3aed 100%);
  --brand-gradient-soft: linear-gradient(135deg, rgba(209,0,201,0.06) 0%, rgba(124,58,237,0.06) 100%);

  /* Neutrals (slate) */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* Semantic */
  --success-50:  #ecfdf5;
  --success-600: #059669;
  --success-700: #047857;
  --error-50:    #fef2f2;
  --error-600:   #dc2626;
  --warn-50:     #fffbeb;
  --warn-600:    #d97706;

  /* Surface */
  --bg:             #f6f7fb;
  --surface:        #ffffff;
  --surface-muted:  #f8fafc;
  --border:         #e5e7ef;
  --border-strong:  #d4d7e3;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(15,23,42,0.04);
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.04), 0 2px 6px rgba(15,23,42,0.04);
  --shadow-md: 0 2px 4px rgba(15,23,42,0.05), 0 8px 24px rgba(15,23,42,0.06);
  --shadow-lg: 0 10px 30px rgba(15,23,42,0.08), 0 24px 48px rgba(15,23,42,0.10);
  --shadow-brand: 0 8px 20px rgba(209,0,201,0.24);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Typography */
  --font-sans: 'Inter', 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* =========================================================================
   Top Progress Bar
   ========================================================================= */

#app-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  z-index: 2000;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}

#app-progress.active { opacity: 1; }

#app-progress .bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 40%;
  height: 100%;
  background: var(--brand-gradient);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 8px rgba(209,0,201,0.5);
  animation: appProgressSweep 1.2s var(--ease-in-out) infinite;
}

@keyframes appProgressSweep {
  0%   { left: -40%; width: 40%; }
  50%  { left: 30%;  width: 60%; }
  100% { left: 100%; width: 40%; }
}

/* =========================================================================
   App Navigation Bar
   ========================================================================= */

.app-nav {
  position: sticky;
  top: 0;
  z-index: 500;
  height: 56px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 10px;
}

.app-nav-logo img {
  height: 34px;
  width: auto;
  display: block;
  filter: drop-shadow(0 2px 6px rgba(209,0,201,0.15));
}

.app-nav-spacer { flex: 1; }

.nav-auth {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Skeleton loader while session fetch is in flight */
.nav-skeleton {
  width: 160px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--slate-100) 25%, var(--slate-200) 50%, var(--slate-100) 75%);
  background-size: 200% 100%;
  animation: navSkeletonShimmer 1.4s var(--ease-in-out) infinite;
}

@keyframes navSkeletonShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Guest buttons */
.nav-btn {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  font-size: 0.86rem;
  font-weight: 600;
  font-family: var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: opacity 160ms var(--ease-out), transform 120ms var(--ease-out), background 160ms var(--ease-out);
  white-space: nowrap;
}
.nav-btn:active { transform: scale(0.97); }

.nav-btn-ghost {
  background: transparent;
  color: var(--slate-600);
  border: 1.5px solid var(--border);
}
.nav-btn-ghost:hover { background: var(--slate-100); color: var(--slate-800); }

.nav-btn-primary {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(209,0,201,0.22);
}
.nav-btn-primary:hover { opacity: 0.88; }

/* Logged-in: avatar pill + dropdown */
.nav-user { position: relative; }

.nav-avatar-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px 0 4px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--slate-700);
  transition: background 160ms var(--ease-out), border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.nav-avatar-btn:hover {
  background: var(--slate-50);
  border-color: rgba(209,0,201,0.35);
  box-shadow: 0 0 0 3px rgba(209,0,201,0.08);
}

.nav-avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-avatar-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-chevron {
  color: var(--slate-400);
  transition: transform 200ms var(--ease-out);
  flex-shrink: 0;
}
.nav-user.open .nav-chevron { transform: rotate(180deg); }

/* Dropdown */
.nav-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  flex-direction: column;
  z-index: 600;
  animation: dropdownFade 160ms var(--ease-out);
}
.nav-user.open .nav-dropdown { display: flex; }

@keyframes dropdownFade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.nav-dropdown-header {
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.nav-dropdown-header .dd-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--slate-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-dropdown-header .dd-role {
  font-size: 0.74rem;
  color: var(--slate-400);
  text-transform: capitalize;
  margin-top: 1px;
}

.nav-dropdown a,
.nav-dropdown button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--slate-700);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 140ms var(--ease-out), color 140ms var(--ease-out);
}
.nav-dropdown a:hover,
.nav-dropdown button:hover {
  background: var(--slate-100);
  color: var(--slate-900);
}
.nav-dropdown a.dd-admin {
  color: var(--brand-500);
  font-weight: 600;
}
.nav-dropdown a.dd-admin:hover { background: rgba(209,0,201,0.07); }

.nav-dropdown .dd-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.nav-dropdown .dd-signout { color: var(--slate-500); }
.nav-dropdown .dd-signout:hover { color: var(--error-600); background: var(--error-50); }

/* Reduce logo-container top spacing now that the nav takes some room */
.logo-container { padding-top: 28px; }

/* =========================================================================
   Base
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--slate-800);
  background:
    radial-gradient(1100px 500px at 50% -120px, rgba(209,0,201,0.08), transparent 60%),
    radial-gradient(900px 500px at 90% 10%, rgba(124,58,237,0.06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

button { font-family: inherit; }

/* =========================================================================
   Header / Logo
   ========================================================================= */

.logo-container {
  display: flex;
  justify-content: center;
  padding: 48px 20px 20px;
}

.udi-logo {
  width: 104px;
  height: auto;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(209,0,201,0.18));
}

/* =========================================================================
   Main Card
   ========================================================================= */

.card {
  background: var(--surface);
  max-width: 460px;
  margin: 0 auto 48px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  padding: 36px 32px 32px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: relative;
  z-index: 1;
}

.scan-heading {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--slate-900);
  margin: 0 0 6px;
  text-align: center;
}

.scan-heading::after {
  content: "Enter a UDI code or scan the barcode on your device";
  display: block;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--slate-500);
  margin-top: 6px;
  letter-spacing: 0;
}

/* =========================================================================
   Search Bar
   ========================================================================= */

.search-bar-outer {
  width: 100%;
  display: flex;
  align-items: center;
  background: var(--surface-muted);
  border-radius: var(--radius-pill);
  padding: 6px 8px 6px 16px;
  margin: 24px 0 20px;
  border: 1.5px solid var(--border);
  transition: border-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out), background 180ms var(--ease-out);
}

.search-bar-outer:focus-within {
  border-color: var(--brand-500);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(209,0,201,0.12);
}

.search-icon {
  display: flex;
  align-items: center;
  color: var(--slate-400);
  margin-right: 4px;
}

.search-icon svg { stroke: currentColor; }

#udi-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 12px 8px;
  outline: none;
  color: var(--slate-900);
}

#udi-input::placeholder { color: var(--slate-400); }

.camera-btn, .upload-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  outline: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 6px;
  padding: 8px;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-pill);
  transition: background 180ms var(--ease-out), transform 180ms var(--ease-out), border-color 180ms var(--ease-out);
}

.camera-btn:hover, .upload-btn:hover {
  background: var(--brand-gradient-soft);
  border-color: rgba(209,0,201,0.28);
  transform: translateY(-1px);
}

.camera-btn:active, .upload-btn:active { transform: translateY(0); }

.camera-btn img, .upload-btn img { width: 18px; height: 18px; }

/* =========================================================================
   Buttons
   ========================================================================= */

.submit-btn {
  width: 100%;
  background: var(--brand-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-top: 4px;
  cursor: pointer;
  box-shadow: var(--shadow-brand);
  transition: transform 180ms var(--ease-out), box-shadow 180ms var(--ease-out), filter 180ms var(--ease-out);
}

.submit-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 10px 24px rgba(209,0,201,0.30);
}

.submit-btn:active { transform: translateY(0); }

.submit-btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.cancel-btn {
  flex: 1;
  background: var(--surface);
  color: var(--slate-700);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 180ms var(--ease-out), border-color 180ms var(--ease-out);
}

.cancel-btn:hover {
  background: var(--slate-100);
  border-color: var(--slate-300);
}

/* =========================================================================
   Scanner
   ========================================================================= */

/* ── Scanner container ──────────────────────────────────────────────────── */
.scanner-container {
  width: 100%;
  margin: 0;
  position: relative;
  background: #000;
  border-radius: 20px;
  overflow: hidden;
  height: 0;
  opacity: 0;
  transition: height 420ms cubic-bezier(.4,0,.2,1),
              opacity 420ms cubic-bezier(.4,0,.2,1),
              margin  420ms cubic-bezier(.4,0,.2,1);
  transform: translateZ(0);
}
.scanner-container.active {
  height: 340px;
  opacity: 1;
  margin: 20px 0 0;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.06);
}

/* Live video */
.scanner-view {
  width: 100%;
  height: 100%;
  position: relative;
  background: #000;
  overflow: hidden;
}
video#html5-qrcode {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
  background: #000;
  position: absolute;
  inset: 0;
  transform: translateZ(0);
  will-change: transform;
}

/* ── HUD overlay ─────────────────────────────────────────────────────────── */
.sc-hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  pointer-events: none;
  z-index: 2;
}

/* Scan frame — box-shadow creates the dark vignette outside it */
.sc-frame {
  position: relative;
  width: clamp(180px, 56vw, 220px);
  height: clamp(180px, 56vw, 220px);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.58);
}

/* Corner brackets — L-shaped, brand purple */
.sc-c {
  position: absolute;
  width: 22px;
  height: 22px;
  border-style: solid;
  border-color: #d100c9;
  border-radius: 2px;
  animation: cornerGlow 2.6s ease-in-out infinite;
}
.sc-c--tl { top: 0;    left: 0;  border-width: 3px 0 0 3px; }
.sc-c--tr { top: 0;    right: 0; border-width: 3px 3px 0 0; animation-delay: .3s; }
.sc-c--bl { bottom: 0; left: 0;  border-width: 0 0 3px 3px; animation-delay: .6s; }
.sc-c--br { bottom: 0; right: 0; border-width: 0 3px 3px 0; animation-delay: .9s; }

@keyframes cornerGlow {
  0%, 100% { border-color: #d100c9; filter: drop-shadow(0 0 0px #d100c9); }
  50%       { border-color: #e879f9; filter: drop-shadow(0 0 5px rgba(209,0,201,.9)); }
}

/* Laser sweep line */
.sc-laser {
  position: absolute;
  left: 5%;
  width: 90%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(209,0,201,.55) 8%,
    #d100c9 50%,
    rgba(209,0,201,.55) 92%,
    transparent 100%);
  box-shadow: 0 0 6px 2px rgba(209,0,201,.75), 0 0 22px 6px rgba(209,0,201,.25);
  animation: laserSweep 2s cubic-bezier(.45,.05,.55,.95) infinite;
}
@keyframes laserSweep {
  0%   { top: 5%;  opacity: .8; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { top: 92%; opacity: .8; }
}

/* Status pill */
.sc-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 10px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 100px;
  color: rgba(255,255,255,0.88);
  font-size: 0.77rem;
  font-weight: 500;
  letter-spacing: .025em;
  white-space: nowrap;
}
.sc-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d100c9;
  flex-shrink: 0;
  animation: dotBreath 1.5s ease-in-out infinite;
  box-shadow: 0 0 4px rgba(209,0,201,.8);
}
@keyframes dotBreath {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%       { transform: scale(.65); opacity: .5; }
}

/* ── Success overlay ────────────────────────────────────────────────────── */
.sc-success {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.52);
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.sc-success.show { opacity: 1; }

.sc-success-ring {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid rgba(34,197,94,.6);
  animation: ringExpand 600ms ease-out forwards;
}
@keyframes ringExpand {
  0%   { transform: scale(.5); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

.sc-success-icon {
  filter: drop-shadow(0 0 14px rgba(34,197,94,.8));
  animation: iconPop 350ms cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes iconPop {
  0%   { transform: scale(.3) rotate(-15deg); opacity: 0; }
  100% { transform: scale(1)  rotate(0deg);   opacity: 1; }
}

/* SVG stroke-draw effect */
.sc-success-circle {
  stroke-dasharray: 157;
  stroke-dashoffset: 157;
  animation: drawCircle 380ms ease-out 60ms forwards;
}
.sc-success-check {
  stroke-dasharray: 36;
  stroke-dashoffset: 36;
  animation: drawCheck 280ms ease-out 340ms forwards;
}
@keyframes drawCircle { to { stroke-dashoffset: 0; } }
@keyframes drawCheck  { to { stroke-dashoffset: 0; } }

/* ── Flip camera button ─────────────────────────────────────────────────── */
.switch-camera-btn {
  position: absolute;
  bottom: 14px;
  right: 14px;
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.14);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 100px;
  padding: 7px 13px 7px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
  z-index: 10;
  transition: background 160ms ease, transform 120ms ease;
}
.switch-camera-btn:hover  { background: rgba(255,255,255,0.24); }
.switch-camera-btn:active { transform: scale(.93); }

/* =========================================================================
   Scan Preview — redesigned
   ========================================================================= */

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.scan-preview {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin: 20px 0 6px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 280ms var(--ease-out);
}

/* ── Header ── */
.sp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(209,0,201,0.04), rgba(124,58,237,0.03));
}

.sp-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand-gradient);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(209,0,201,0.28);
}

.sp-title {
  font-size: 0.95rem; font-weight: 700;
  color: var(--slate-900); letter-spacing: -0.01em;
}
.sp-sub {
  font-size: 0.78rem; color: var(--slate-500); margin-top: 1px;
}

/* ── Raw UDI chip ── */
.sp-raw {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--border);
}

.sp-raw-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--slate-400);
  flex-shrink: 0;
}

.sp-raw-value {
  flex: 1; min-width: 0;
  font-family: var(--font-mono); font-size: 0.78rem;
  color: var(--slate-700); word-break: break-all; line-height: 1.4;
}

.sp-copy-btn {
  flex-shrink: 0; background: none; border: none;
  padding: 5px; border-radius: 6px; cursor: pointer;
  color: var(--slate-400); display: flex; align-items: center;
  transition: background 140ms, color 140ms;
}
.sp-copy-btn:hover { background: var(--slate-200); color: var(--slate-700); }
.sp-copy-btn.copied { color: var(--success-600); background: var(--success-50); }

/* ── Sections ── */
.sp-section {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.sp-section:last-of-type { border-bottom: none; }

.sp-section-title {
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--brand-500);
  margin-bottom: 10px;
}

/* Hero field — UDI-DI */
.sp-field--hero .sp-field-value {
  font-size: 1rem; font-weight: 700; color: var(--slate-900);
  letter-spacing: 0.04em;
}

.sp-field {
  display: flex; flex-direction: column; gap: 2px;
  padding: 4px 0;
}

.sp-field-label {
  font-size: 0.72rem; font-weight: 600;
  color: var(--slate-500);
  display: flex; align-items: center; gap: 5px;
}

.sp-ai-tag {
  font-size: 0.62rem; font-weight: 700;
  background: var(--slate-100); color: var(--slate-500);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 0 4px; line-height: 1.6;
}

.sp-field-value {
  font-family: var(--font-mono); font-size: 0.88rem; font-weight: 600;
  color: var(--slate-800); word-break: break-all;
}

.sp-field-value.empty {
  font-family: var(--font-sans); font-size: 0.82rem;
  font-style: italic; font-weight: 400; color: var(--slate-400);
}

.sp-field-value--exp { color: var(--warn-600); }

/* Barcode symbology badge in the section title */
.sp-format-badge {
  font-size: 0.58rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--brand-500, #7c3aed); color: #fff;
  border-radius: 4px; padding: 2px 7px;
  vertical-align: middle; margin-left: 6px;
  white-space: nowrap;
}

/* Expired: stronger red override, plus inline EXPIRED badge */
.sp-field-value--expired { color: #dc2626 !important; }
.sp-expired-badge {
  display: inline-flex; align-items: center;
  font-size: 0.58rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
  background: #dc2626; color: #fff;
  border-radius: 3px; padding: 1px 5px;
  vertical-align: middle; margin-left: 4px;
}

/* Empty state when no GS1 fields detected */
.sp-empty-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--slate-500);
  font-size: 0.85rem;
  line-height: 1.7;
}
.sp-empty-icon {
  font-size: 1.6rem;
  margin-bottom: 8px;
  color: var(--slate-300);
}

/* Production grid: 2 cols on ≥400px */
.sp-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px 20px;
}
@media (min-width: 400px) {
  .sp-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Action buttons ── */
.preview-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border);
}
@media (min-width: 400px) {
  .preview-actions { flex-direction: row; }
  .preview-actions .submit-btn { flex: 1; }
  .preview-actions .cancel-btn { flex: 1; }
}
.preview-actions .submit-btn,
.preview-actions .cancel-btn { margin-top: 0; }

/* keep old .copy-btn selector for any lingering references */
.copy-btn {
  background: transparent; border: none; padding: 4px; cursor: pointer;
  border-radius: var(--radius-sm); color: var(--slate-500);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 180ms var(--ease-out), color 180ms var(--ease-out);
}
.copy-btn:hover { background: var(--slate-100); color: var(--slate-700); }
.copy-btn.copied { background: var(--success-50); color: var(--success-700); }

.preview-row {
  display: flex; flex-direction: column; gap: 2px; padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.preview-row:last-child { border-bottom: none; }
.preview-row .label { color: var(--slate-500); font-size: 0.75rem; font-weight: 600; }
.preview-row .value { color: var(--slate-900); font-family: var(--font-mono); font-size: 0.88rem; font-weight: 600; word-break: break-all; }
.preview-row .value.empty { color: var(--slate-400); font-family: var(--font-sans); font-style: italic; font-weight: 400; }

/* =========================================================================
   Modal / Bottom Sheet — redesigned
   ========================================================================= */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15,23,42,0.48);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Class-toggled open state */
.modal.is-open { display: flex; }

/* ── Shared sheet styles ── */
.modal-sheet {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Mobile: bottom sheet ── */
@media (max-width: 639px) {
  .modal.is-open {
    align-items: flex-end;
    padding: 0;
  }
  .modal-sheet {
    width: 100%;
    max-height: 92svh;
    max-height: 92vh;
    border-radius: 24px 24px 0 0;
    animation: sheetUp 300ms var(--ease-out);
  }
  @keyframes sheetUp {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
}

/* ── Desktop: centered dialog ── */
@media (min-width: 640px) {
  .modal.is-open {
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
  }
  .modal-sheet {
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: sheetFade 220ms var(--ease-out);
  }
  @keyframes sheetFade {
    from { transform: translateY(10px) scale(0.98); opacity: 0; }
    to   { transform: translateY(0) scale(1);       opacity: 1; }
  }
  .modal-drag-handle { display: none; }
}

/* ── Drag handle (mobile only) ── */
.modal-drag-handle {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 12px 0 4px;
}
.modal-drag-handle::after {
  content: '';
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--slate-200);
}

/* ── Modal header ── */
.modal-header {
  flex-shrink: 0;
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--slate-900);
  letter-spacing: -0.01em;
}

.modal-close-btn {
  flex-shrink: 0;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  border-radius: var(--radius-pill);
  color: var(--slate-500);
  transition: background 160ms, color 160ms;
}
.modal-close-btn:hover { background: var(--slate-100); color: var(--slate-900); }

.modal-udi-code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--slate-600);
  background: var(--slate-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  word-break: break-all;
  overflow-wrap: break-word;
  line-height: 1.5;
}

/* ── Modal body (scrollable) ── */
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}

/* ── Modal footer (review form) ── */
.modal-footer {
  flex-shrink: 0;
  padding: 0 20px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.modal-divider {
  height: 1px;
  background: var(--border);
  margin: 0 0 16px;
}

/* ── Source badges ── */
.source-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.6rem; font-weight: 800;
  letter-spacing: 0.07em; text-transform: uppercase;
  vertical-align: middle; line-height: 1.6;
}
.source-badge--local {
  background: rgba(209,0,201,0.10); color: var(--brand-500);
  border: 1px solid rgba(209,0,201,0.25);
}
.source-badge--eudamed {
  background: rgba(109,40,217,0.10); color: var(--accent-500);
  border: 1px solid rgba(109,40,217,0.25);
}
.source-badge--scan {
  background: rgba(5,150,105,0.10); color: var(--success-700,#047857);
  border: 1px solid rgba(5,150,105,0.25);
}

/* ── Device info cards (EUDAMED + local) ── */
.eudamed-info {
  margin-bottom: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(124,58,237,0.18);
  border-left: 3px solid var(--accent-500);
  overflow: hidden;
}
.eudamed-info.eudamed-info--local {
  border-left-color: var(--brand-500);
  border-color: rgba(209,0,201,0.18);
}
/* "This Label" card — shows parsed GS1 AIs from the actual scanned barcode */
.eudamed-info.eudamed-info--scan {
  border-left-color: var(--success-600,#059669);
  border-color: rgba(5,150,105,0.18);
}
.eudamed-info.eudamed-info--scan .eudamed-title {
  background: linear-gradient(135deg, rgba(5,150,105,0.06), rgba(5,150,105,0.02));
  color: var(--success-700,#047857);
  border-bottom-color: rgba(5,150,105,0.12);
}

.eudamed-info .eudamed-title {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px 8px;
  background: linear-gradient(135deg, rgba(124,58,237,0.05), rgba(124,58,237,0.02));
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--accent-500);
  border-bottom: 1px solid rgba(124,58,237,0.12);
}
.eudamed-info.eudamed-info--local .eudamed-title {
  background: linear-gradient(135deg, rgba(209,0,201,0.06), rgba(209,0,201,0.02));
  color: var(--brand-500);
  border-bottom-color: rgba(209,0,201,0.12);
}

/* Two-column data grid */
.eudamed-info .eudamed-rows {
  display: grid;
  grid-template-columns: 1fr;
  padding: 8px 0;
}
@media (min-width: 400px) {
  .eudamed-info .eudamed-rows { grid-template-columns: 1fr 1fr; }
}

.eudamed-info .eudamed-row {
  display: flex; flex-direction: column; gap: 1px;
  padding: 7px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}
.eudamed-info .eudamed-row:last-child { border-bottom: none; }

.eudamed-info .eudamed-row .k {
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--slate-400);
}
.eudamed-info .eudamed-row .v {
  font-size: 0.88rem; font-weight: 600;
  color: var(--slate-900); word-break: break-word;
}

.eudamed-info .eudamed-link {
  display: inline-flex; align-items: center; gap: 4px;
  margin: 4px 14px 10px;
  font-size: 0.82rem; font-weight: 600;
  color: var(--accent-500); text-decoration: none;
  transition: opacity 150ms;
}
.eudamed-info .eudamed-link:hover { opacity: 0.75; }

/* ── Review list ── */
.reviews-heading {
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--slate-400);
  margin-bottom: 8px; margin-top: 4px;
}

.reviews-list { list-style: none; padding: 0; margin: 0 0 4px; }

.review-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.review-item:last-child { border-bottom: none; }

.review-stars { font-size: 1rem; color: #f59e0b; letter-spacing: 1px; }
.review-stars-empty { color: var(--slate-200); }

.review-comment-text {
  color: var(--slate-700); font-size: 0.9rem;
  line-height: 1.55; margin-top: 5px; word-break: break-word;
}

.review-meta {
  font-size: 0.74rem; color: var(--slate-400);
  margin-top: 5px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}

.reviewer-role {
  display: inline-flex; align-items: center;
  padding: 1px 7px; border-radius: var(--radius-pill);
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em;
  border: 1px solid; vertical-align: middle;
}
.reviewer-anon { font-size: 0.74rem; color: var(--slate-400); font-style: italic; }

.review-summary {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.88rem; color: var(--slate-600);
  background: var(--slate-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px; margin-bottom: 12px;
}

#modal-reviews-section {
  width: 100%; text-align: left;
  font-size: 0.95rem; color: var(--slate-700);
}

/* ── Review form ── */
.review-form-heading {
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--slate-500);
  margin-bottom: 12px;
}

.star-rating {
  display: flex; gap: 6px;
  margin-bottom: 14px; justify-content: center;
}
.star-rating .star {
  font-size: 32px; line-height: 1;
  color: var(--slate-200); cursor: pointer;
  transition: color 160ms var(--ease-out), transform 160ms var(--ease-out);
  user-select: none; padding: 2px 3px;
}
.star-rating .star:hover   { transform: scale(1.15); }
.star-rating .star.selected { color: #f59e0b; }
.star-rating .star.hover   { color: #fbbf24; }

#review-comment {
  width: 100%; min-height: 80px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  padding: 11px 14px;
  font-family: var(--font-sans); font-size: 0.92rem;
  color: var(--slate-900); margin-bottom: 14px;
  resize: vertical; background: var(--surface-muted); outline: none;
  transition: border-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out), background 180ms var(--ease-out);
}
#review-comment::placeholder { color: var(--slate-400); }
#review-comment:focus {
  border-color: var(--brand-500); background: var(--surface);
  box-shadow: 0 0 0 4px rgba(209,0,201,0.10);
}

/* Sign-in prompt */
.review-signin-prompt {
  display: flex; flex-direction: column;
  align-items: center; text-align: center;
  padding: 4px 0; gap: 6px;
}
.review-signin-prompt p {
  margin: 0 0 12px; font-size: 0.88rem; color: var(--slate-500);
}
.review-signin-btn { width: auto !important; padding: 12px 28px !important; }

/* ── Status messages ── */
.modal-message {
  width: 100%; text-align: center; margin-bottom: 12px;
  font-size: 0.88rem; padding: 10px 14px;
  border-radius: var(--radius-md); font-weight: 500;
}
.modal-message.error {
  background: var(--error-50); color: var(--error-600);
  border: 1px solid #fecaca;
}
.modal-message.success {
  background: var(--success-50); color: var(--success-700);
  border: 1px solid #a7f3d0;
}

/* ── Spinner ── */
.spinner {
  display: inline-block; width: 26px; height: 26px;
  border: 3px solid var(--slate-200); border-top-color: var(--brand-500);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   Results Section
   ========================================================================= */

#results-section {
  max-width: 800px;
  margin: 0 auto 48px;
  padding: 0 20px;
}

/* =========================================================================
   Support Section
   ========================================================================= */

.support-section {
  background: linear-gradient(180deg, transparent 0%, #f2f4fa 100%);
  padding: 72px 20px 56px;
  border-top: 1px solid var(--border);
  width: 100%;
}

.support-container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}

.support-section h2 {
  color: var(--slate-900);
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
  text-align: center;
}

.support-intro {
  color: var(--slate-600);
  font-size: 1.02rem;
  line-height: 1.65;
  margin: 0 auto 48px;
  max-width: 760px;
  text-align: center;
}

.support-flex-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin: 0 auto;
  max-width: 1120px;
  padding: 0 20px;
}

.donation-info {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.support-video {
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  position: relative;
  aspect-ratio: 9 / 16;
  background: #000;
}

.support-video::before { content: none; }

.support-video video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.donation-info h3 {
  color: var(--slate-900);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 18px;
  letter-spacing: -0.01em;
}

.donation-benefits {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
}

.donation-benefits li {
  color: var(--slate-700);
  font-size: 0.98rem;
  margin-bottom: 12px;
  padding-left: 32px;
  position: relative;
  line-height: 1.5;
}

.donation-benefits li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand-gradient);
  background-image: var(--brand-gradient),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'><path d='M5 10.5l3.2 3.2L15 7' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-size: cover;
  background-position: center;
  box-shadow: 0 2px 6px rgba(209,0,201,0.25);
}

.donate-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-gradient);
  color: #fff;
  text-decoration: none;
  padding: 14px 26px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-brand);
  transition: transform 180ms var(--ease-out), filter 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
  margin: 8px auto 0;
  text-align: center;
  width: 100%;
  max-width: 280px;
}

.donate-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 10px 24px rgba(209,0,201,0.32);
}

.thank-you {
  color: var(--slate-500);
  font-size: 0.92rem;
  font-style: italic;
  margin: 18px 0 0;
  text-align: center;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 900px) {
  .support-flex-container {
    grid-template-columns: 1fr;
    gap: 32px;
    max-width: 600px;
  }
}

@media (max-width: 600px) {
  .logo-container { padding: 32px 16px 12px; }
  .udi-logo { width: 80px; }

  .card {
    max-width: calc(100vw - 24px);
    margin: 0 12px 32px;
    padding: 24px 20px 22px;
    border-radius: var(--radius-lg);
  }

  .scan-heading { font-size: 1.25rem; }
  .scan-heading::after { font-size: 0.85rem; }

  .search-bar-outer { padding: 4px 6px 4px 14px; }
  #udi-input { font-size: 0.95rem; padding: 11px 6px; }
  .camera-btn, .upload-btn { width: 36px; height: 36px; }

  .submit-btn { padding: 13px 18px; font-size: 0.98rem; }

  .scanner-container.active { height: 260px; }
  .scanner-view::after { width: 170px; height: 170px; }

  .support-section { padding: 48px 16px 40px; }
  .support-section h2 { font-size: 1.5rem; }
  .support-intro { font-size: 0.98rem; margin-bottom: 32px; }
  .donation-info { padding: 24px 20px; }
  .donation-benefits li { font-size: 0.92rem; padding-left: 28px; }
  .donate-button { padding: 12px 22px; font-size: 0.96rem; }
}
