/* ============================================================
   ORGANIXS - Custom Styles (matches original design system)
   ============================================================ */

:root {
  --background: hsl(220, 13%, 94%);
  --foreground: hsl(220, 9%, 10%);
  --card: hsl(0, 0%, 100%);
  --card-foreground: hsl(220, 9%, 10%);
  --primary: hsl(225, 65%, 30%);
  --primary-foreground: hsl(0, 0%, 100%);
  --secondary: hsl(220, 13%, 90%);
  --secondary-foreground: hsl(220, 9%, 25%);
  --muted: hsl(220, 13%, 85%);
  --muted-foreground: hsl(220, 9%, 45%);
  --accent: hsl(120, 61%, 50%);
  --accent-foreground: hsl(0, 0%, 100%);
  --destructive: hsl(0, 84.2%, 60.2%);
  --destructive-foreground: hsl(0, 0%, 98%);
  --border: hsl(220, 13%, 88%);
  --input: hsl(220, 13%, 92%);
  --ring: hsl(225, 65%, 40%);
  --radius: 0.5rem;
  --sidebar-bg: hsl(230, 15%, 12%);
  --sidebar-fg: hsl(220, 13%, 80%);
  --sidebar-primary: hsl(225, 65%, 55%);
  --sidebar-accent: hsl(230, 15%, 22%);
  --sidebar-border: hsl(230, 15%, 22%);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---- Card ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-header { padding: 1.5rem; }
.card-content { padding: 0 1.5rem 1.5rem; }
.card-footer { padding: 0 1.5rem 1.5rem; }
.card-title { font-size: 1.125rem; font-weight: 600; line-height: 1.3; }
.card-description { font-size: 0.875rem; color: var(--muted-foreground); margin-top: 0.25rem; }

.card-shadow { box-shadow: 0 25px 50px -12px rgba(0,0,0,.25); }

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25rem;
  white-space: nowrap;
}
.badge-default { background: var(--primary); color: var(--primary-foreground); }
.badge-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.badge-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.badge-green { background: hsl(120, 61%, 50%); color: white; }
.badge-amber { background: hsl(38, 92%, 50%); color: white; }
.badge-outline { border: 1px solid var(--border); background: transparent; }

/* ---- Button ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  line-height: 1.25rem;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover:not(:disabled) { opacity: 0.9; }
.btn-accent { background: var(--accent); color: var(--accent-foreground); }
.btn-accent:hover:not(:disabled) { background: hsl(120, 61%, 45%); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--foreground); }
.btn-outline:hover:not(:disabled) { background: var(--secondary); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover:not(:disabled) { background: var(--secondary); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-full { width: 100%; }
.btn-icon { padding: 0.5rem; }

/* ---- Input ---- */
.input {
  display: flex;
  height: 2.5rem;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--foreground);
  outline: none;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.input:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px hsla(225, 65%, 40%, 0.2);
}
.input::placeholder { color: var(--muted-foreground); }
.input-lg {
  height: 4rem;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* ---- Table ---- */
.table-container { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 500;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: hsla(220, 13%, 94%, 0.5); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---- Layout ---- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: start; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }
.w-full { width: 100%; }
.max-w-md { max-width: 28rem; }
.min-h-screen { min-height: 100vh; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.pt-2 { padding-top: 0.5rem; }
.pt-4 { padding-top: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-2 { margin-top: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.ml-1 { margin-left: 0.25rem; }
.mr-2 { margin-right: 0.5rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.overflow-hidden { overflow: hidden; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-full { border-radius: 9999px; }
.border { border: 1px solid var(--border); }
.border-t { border-top: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.shadow-md { box-shadow: 0 4px 6px -1px rgba(0,0,0,.1); }
.hidden { display: none !important; }
.select-none { user-select: none; -webkit-user-select: none; }

/* ---- Typography ---- */
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-4xl { font-size: 2.25rem; }
.font-mono { font-family: ui-monospace, SFMono-Regular, 'SF Mono', monospace; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-black { font-weight: 900; }
.tracking-widest { letter-spacing: 0.1em; }
.uppercase { text-transform: uppercase; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-clamp-5 {
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.text-muted { color: var(--muted-foreground); }
.text-primary { color: var(--primary); }
.text-green { color: hsl(120, 61%, 40%); }
.text-amber { color: hsl(38, 92%, 50%); }
.text-destructive { color: var(--destructive); }
.text-white { color: white; }
.underline { text-decoration: underline; }
.leading-relaxed { line-height: 1.625; }
.whitespace-nowrap { white-space: nowrap; }
.tabular-nums { font-variant-numeric: tabular-nums; }

/* ---- Loading Spinner ---- */
.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-lg { width: 3rem; height: 3rem; border-width: 3px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Toast Notification ---- */
.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 24rem;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,.1);
  animation: slideIn 0.3s ease;
}
.toast-title { font-weight: 600; font-size: 0.875rem; }
.toast-desc { font-size: 0.8125rem; color: var(--muted-foreground); margin-top: 0.25rem; }
.toast-destructive { border-color: var(--destructive); }
.toast-destructive .toast-title { color: var(--destructive); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   SIDEBAR LAYOUT
   ============================================================ */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: transform 0.3s ease;
}
.sidebar-header {
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-header img { max-width: 130px; height: auto; }
.sidebar-content {
  flex: 1;
  padding: 0.5rem 0;
  overflow-y: auto;
}
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-menu { list-style: none; padding: 0.25rem 0.5rem; }
.sidebar-menu-item { margin-bottom: 2px; }
.sidebar-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  color: var(--sidebar-fg);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.sidebar-menu-btn:hover { background: var(--sidebar-accent); color: white; }
.sidebar-menu-btn.active { background: var(--sidebar-primary); color: white; }
.sidebar-menu-btn svg { width: 1.125rem; height: 1.125rem; flex-shrink: 0; }

/* Main content area */
.main-area {
  flex: 1;
  margin-left: 250px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.top-header {
  display: flex;
  align-items: center;
  height: 60px;
  padding: 0 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.main-content {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--foreground);
  cursor: pointer;
  padding: 0.5rem;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 35;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-area { margin-left: 0; }
  .sidebar-toggle { display: block; }
  .grid-cols-3 { grid-template-columns: 1fr; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   USER NAV / AVATAR / DROPDOWN
   ============================================================ */
.user-nav { position: relative; margin-left: auto; }
.avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  border: none;
}
.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  width: 14rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(0,0,0,.12);
  z-index: 50;
  display: none;
  overflow: hidden;
}
.dropdown.open { display: block; }
.dropdown-label {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.dropdown-label p { font-size: 0.875rem; font-weight: 500; }
.dropdown-label .email { font-size: 0.75rem; color: var(--muted-foreground); margin-top: 0.125rem; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: none;
  border: none;
  font-size: 0.875rem;
  color: var(--foreground);
  cursor: pointer;
  text-align: left;
}
.dropdown-item:hover { background: var(--secondary); }
.dropdown-sep { height: 1px; background: var(--border); }

/* ============================================================
   DIALOG / MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.hidden {
  display: none;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 42rem;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,.25);
}
.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 1.125rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted-foreground);
  padding: 0.25rem;
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
}
.modal-footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ---- Certificate Popup (full-screen modal) ---- */
.cert-modal {
  max-width: 56rem;
  width: 95vw;
  height: 95vh; /* Increased from 90vh for better visibility */
  max-height: 95vh;
}
.cert-modal .modal-body {
  position: relative;
  padding: 0;
  background: var(--muted);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%; /* Ensure full height usage */
  overflow: hidden; /* Remove scroll bars from modal body */
}
.cert-iframe-wrapper {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  z-index: 10;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.cert-iframe-wrapper.hidden {
  display: none;
}
.cert-iframe-wrapper::-webkit-scrollbar { display: none; }
.cert-viewer {
  position: relative;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  z-index: 10;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 1rem;
  align-items: center;
  box-sizing: border-box;
  height: 100%; /* Ensure full height */
}
.cert-viewer.hidden {
  display: none;
}
.cert-loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.16);
  color: var(--foreground);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.cert-diagnostics {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 35;
  border-radius: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(220, 38, 38, 0.95);
  color: white;
  font-size: 0.875rem;
  line-height: 1.4;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  white-space: pre-wrap;
}
.cert-diagnostics.hidden {
  display: none;
}
.pdf-page {
  display: block;
  max-width: 1000px;
  min-height: 170%;
  margin: 0 auto 1rem auto; /* Added bottom margin for spacing */
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.16);
  background: var(--background);
  break-inside: avoid; /* Prevent page breaks within PDF pages */
}
.pdf-page canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: -webkit-optimize-contrast; /* Better text rendering */
  image-rendering: crisp-edges;
}
.cert-iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.cert-shield {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: transparent;
  cursor: default;
  pointer-events: none;
}
.cert-watermark {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0.03;
  transform: rotate(-45deg);
  user-select: none;
}
.cert-watermark div {
  font-size: 2.25rem;
  font-weight: 900;
  white-space: nowrap;
  line-height: 2;
  letter-spacing: 0.1em;
}
.cert-secure-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 40;
  pointer-events: none;
  background: hsla(225, 65%, 30%, 0.9);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}
.cert-footer {
  font-size: 0.625rem;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* ---- Mobile PDF Modal Adjustments ---- */
@media (max-width: 768px) {
  .cert-modal {
    width: 98vw;
    height: 95vh;
    max-width: none;
  }

  .cert-viewer {
    padding: 0.5rem; /* Reduce padding on mobile */
    gap: 0.5rem;
  }

  .pdf-page {
    max-width: 100%; /* Allow full width on mobile */
    min-height: 125%; /* Remove fixed min-height on mobile */
    margin: 0 auto 0.5rem auto;
  }

  .pdf-page canvas {
    max-width: 100%;
    height: auto;
  }
}

/* ---- Scan result specific ---- */
.scan-center {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: var(--background);
  padding: 1rem;
}
.scan-card-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.5rem;
  background: var(--card);
}
.scan-card-content {
  padding: 1.5rem;
  background: var(--background);
}
.scan-icon svg { width: 3rem; height: 3rem; }
.product-image {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}
.batch-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  background: hsla(220, 13%, 85%, 0.3);
  padding: 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  margin-bottom: 0.5rem;
}
.batch-label {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-foreground);
  font-weight: 600;
}
.batch-value {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--foreground);
}

/* ---- Form label ---- */
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}
.form-error {
  font-size: 0.8125rem;
  color: var(--destructive);
  margin-top: 0.25rem;
}
.form-group { margin-bottom: 1rem; }

/* ---- Muted hint box ---- */
.hint-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  border-radius: 0.5rem;
  background: hsla(220, 13%, 85%, 0.5);
  padding: 1rem;
  color: var(--muted-foreground);
}
.hint-box svg { width: 2rem; height: 2rem; }
.hint-box span { font-size: 0.875rem; margin-top: 0.5rem; text-align: center; padding: 0 1rem; }

/* ---- Print/context protection ---- */
@media print {
  body * { display: none !important; }
}

/* ---- Skeleton loading ---- */
.skeleton {
  background: var(--muted);
  border-radius: var(--radius);
  animation: pulse 1.5s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ---- Status dot on card ---- */
.border-destructive-soft {
  border-color: hsla(0, 84.2%, 60.2%, 0.5);
}
