/* ===== BIOBANK TRACKER — Design System ===== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f0f2f5;
  --bg-dark: #e4e7ec;
  --panel: #ffffff;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --nav-height: 56px;
}

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

/* Global: inline SVGs should never be full-width block elements */
svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

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

/* ===== LAYOUT SHELL ===== */

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Top Navbar --- */

.navbar {
  height: var(--nav-height);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary);
  white-space: nowrap;
}

.nav-brand svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.nav-links svg {
  width: 16px;
  height: 16px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
}

.nav-links a,
.nav-links button.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s;
  white-space: nowrap;
  width: auto;
}

.nav-links a:hover,
.nav-links button.nav-link:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-links a.active,
.nav-links button.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-center-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 600;
  color: var(--primary);
}

.nav-center-badge svg {
  width: 14px;
  height: 14px;
}

.nav-center-badge select {
  border: none;
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  font-size: .8rem;
  padding: 0;
  cursor: pointer;
  width: auto;
}

.nav-center-badge select:focus {
  outline: none;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--text-secondary);
}

.nav-user .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .75rem;
  flex-shrink: 0;
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 500;
  color: var(--danger);
  background: var(--danger-light);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  width: auto;
}

.btn-logout svg {
  width: 14px;
  height: 14px;
}

.btn-logout:hover {
  border-color: var(--danger);
  background: #fee2e2;
}

/* --- Page Content --- */

.page-content {
  flex: 1;
  padding: 24px 20px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* ===== TYPOGRAPHY ===== */

h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 4px; }
h2 { font-size: 1.25rem; font-weight: 700; margin: 0 0 4px; }
h3 { font-size: 1.1rem; font-weight: 600; margin: 0 0 4px; }
.subtitle { font-size: .9rem; color: var(--text-secondary); margin: 0 0 20px; }

/* ===== CARDS ===== */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-header h2,
.card-header h3 {
  margin: 0;
}

/* ===== GRID ===== */

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.gap-24 { gap: 24px; }

/* ===== DASHBOARD TILES ===== */

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  cursor: pointer;
  transition: all .2s ease;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--text);
  min-height: 200px;
}

.tile:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.tile:active {
  transform: translateY(0);
}

.tile-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-icon svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.tile-icon.blue {
  background: var(--primary-light);
  color: var(--primary);
}

.tile-icon.emerald {
  background: var(--success-light);
  color: var(--success);
}

.tile-icon.amber {
  background: var(--warning-light);
  color: var(--warning);
}

.tile-label {
  font-size: 1.15rem;
  font-weight: 700;
}

.tile-desc {
  font-size: .85rem;
  color: var(--text-secondary);
  text-align: center;
}

/* ===== FORMS ===== */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 2px;
}

input,
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  transition: border-color .15s, box-shadow .15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

input.scan-ok {
  border-color: var(--success) !important;
  box-shadow: 0 0 0 3px rgba(5,150,105,.15) !important;
  animation: scanPulse .5s ease;
}

@keyframes scanPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.01); }
  100% { transform: scale(1); }
}

textarea {
  resize: vertical;
  min-height: 60px;
}

/* ===== BUTTONS ===== */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .1s;
  white-space: nowrap;
  width: auto;
}

/* Inline SVG icons inside buttons must never stretch */
button svg, .btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

button.btn-sm svg, .btn-sm svg {
  width: 14px;
  height: 14px;
}

button:active {
  transform: scale(.98);
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary, button {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-dark);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg);
}

.btn-sm {
  padding: 5px 10px;
  font-size: .78rem;
}

.btn-full {
  width: 100%;
}

/* ===== TABLES ===== */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead {
  background: var(--bg);
}

th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: .78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr {
  transition: background .1s;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--primary-light);
}

tbody tr.clickable {
  cursor: pointer;
}

/* ===== PAGINATION ===== */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 0 4px;
}

.pagination button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  font-size: .8rem;
}

.pagination button:hover:not(:disabled) {
  background: var(--bg);
}

.pagination .page-info {
  font-size: .8rem;
  color: var(--muted);
  padding: 0 8px;
}

/* ===== TOAST ===== */

#toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 9999;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
  max-width: 380px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: #1e40af; }

/* ===== MODAL ===== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  animation: fadeIn .15s ease;
}

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

.modal {
  width: min(640px, 100%);
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* ===== SEARCH BAR ===== */

.search-bar {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.search-bar input {
  flex: 1;
}

.search-bar button {
  flex-shrink: 0;
}

.search-bar button svg {
  width: 16px;
  height: 16px;
}

/* ===== FILTER BAR (database view) ===== */

.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-search {
  flex: 1;
  min-width: 200px;
}

.filter-search input {
  width: 100%;
}

.filter-dates {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.date-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.date-field label {
  margin: 0;
  font-size: .7rem;
}

.date-field input[type="date"] {
  width: 150px;
  padding: 8px 10px;
  font-size: .82rem;
}

.date-sep {
  color: var(--muted);
  font-size: .85rem;
  padding-bottom: 10px;
}

.filter-actions {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

/* ===== DATE PRESETS ===== */

.date-presets {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.preset-btn {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .15s;
}

.preset-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.preset-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

@media (max-width: 768px) {
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-dates {
    flex-wrap: wrap;
  }
  .date-field input[type="date"] {
    width: 100%;
  }
  .filter-search {
    min-width: unset;
  }
}

/* ===== EXPORT TOOLBAR ===== */

.export-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  animation: fadeIn .15s ease;
}

.export-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--primary);
}

.export-info svg {
  width: 18px;
  height: 18px;
}

.export-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-export {
  background: #059669;
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s;
}

.btn-export:hover:not(:disabled) {
  background: #047857;
}

.btn-export:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.btn-export svg {
  width: 16px;
  height: 16px;
}

/* ===== ROW SELECTION & EXPORT STATUS ===== */

tr.row-selected {
  background: var(--primary-light) !important;
}

tr.row-exported {
  background: #f0fdf4;
}

tr.row-exported:hover {
  background: #dcfce7 !important;
}

.badge-exported {
  background: var(--success-light);
  color: var(--success);
  font-size: .68rem;
  padding: 2px 6px;
}

/* Checkbox in table */
th input[type="checkbox"],
td input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

.patient-link {
  color: var(--primary);
  cursor: pointer;
}

.patient-link:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  .export-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .export-actions {
    justify-content: flex-end;
  }
}

/* ===== BADGE / CHIP ===== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}

.badge-active { background: var(--success-light); color: var(--success); }
.badge-inactive { background: var(--bg); color: var(--muted); }
.badge-admin { background: var(--primary-light); color: var(--primary); }
.badge-worker { background: var(--warning-light); color: var(--warning); }

/* ===== STEP INDICATOR (scanning wizard) ===== */

.scan-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--primary);
  font-weight: 500;
}

.scan-status strong {
  font-size: 1.05rem;
}

/* ===== LOGIN ===== */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eff6ff 0%, #dbeafe 40%, #c7d2fe 100%);
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border-radius: var(--radius-xl);
  padding: 36px 32px 28px;
  box-shadow: 0 20px 60px rgba(37, 99, 235, .12), 0 4px 12px rgba(0,0,0,.06);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  background: var(--primary-light);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.login-logo svg {
  width: 26px;
  height: 26px;
}

.login-header h1 {
  font-size: 1.35rem;
  margin: 0 0 4px;
}

.login-subtitle {
  font-size: .85rem;
  color: var(--text-secondary);
  margin: 0;
}

.login-footer {
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  margin: 20px 0 0;
}

/* ===== TOGGLE SWITCH ===== */

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background .2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

.toggle input:checked + .toggle-slider {
  background: var(--success);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

.toggle input:focus + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(5,150,105,.2);
}

/* ===== SCANNER MODE TOOLBAR ===== */

.scan-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.scan-mode-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.scan-mode-switch .mode-label {
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
}

.mode-local { background: var(--primary-light); color: var(--primary); }
.mode-mobile { background: var(--success-light); color: var(--success); }

.mobile-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--muted);
}

.mobile-status .ws-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
}

.ws-dot.connected { background: var(--success); }

/* ===== QR PANEL (mobile mode) ===== */

.qr-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.qr-panel img, .qr-panel svg {
  width: 140px;
  height: 140px;
  border-radius: var(--radius-sm);
  background: #fff;
  flex-shrink: 0;
}

.qr-panel-info {
  flex: 1;
  font-size: .85rem;
  color: var(--text-secondary);
}

.qr-panel-info strong {
  display: block;
  font-size: .95rem;
  color: var(--text);
  margin-bottom: 4px;
}

/* ===== SCANNABLE FIELD (lockable) ===== */

.scannable-wrap {
  position: relative;
}

.scannable-wrap input {
  padding-right: 36px;
}

.scannable-wrap input.locked {
  background: var(--bg);
  color: var(--text);
  border-color: var(--success);
  pointer-events: none;
}

.lock-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}

.lock-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.lock-btn.is-locked {
  color: var(--success);
  border-color: var(--success);
  background: var(--success-light);
}

.lock-btn svg {
  width: 14px;
  height: 14px;
}

/* ===== EMPTY STATE ===== */

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  display: block;
  opacity: .4;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page-content { padding: 16px 12px 32px; }
  .navbar { padding: 0 12px; }
  .nav-links { display: none; }
  .card { padding: 16px; }
  .tile { min-height: 140px; padding: 24px 16px; }
  .login-card { padding: 28px 20px; }
}

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