:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --success: #16a34a;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --text-secondary: #6b7280;
  --border: #d1d5db;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header h1 { font-size: 18px; font-weight: 600; }
.header .user-info { font-size: 13px; opacity: 0.9; }
.header button {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
}

/* Page container */
.page { padding: 16px; padding-bottom: 80px; max-width: 600px; margin: 0 auto; }

/* Card */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* Form elements */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-secondary);
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:active { background: var(--danger-dark); }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-sm {
  display: inline-block;
  width: auto;
  padding: 6px 14px;
  font-size: 13px;
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

/* Barcode input - large & prominent */
.barcode-input {
  font-size: 24px !important;
  padding: 16px !important;
  text-align: center;
  letter-spacing: 2px;
}
.barcode-input:focus {
  box-shadow: 0 0 0 4px rgba(37,99,235,0.2);
}

.barcode-display {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  word-break: break-all;
  padding: 12px;
  background: #eff6ff;
  border-radius: var(--radius);
  margin: 12px 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.barcode-display.active { color: var(--text); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 12px;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
}
.bottom-nav a.active { color: var(--primary); }

/* Record list */
.record-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}
.record-card .product-code {
  font-size: 16px;
  font-weight: 600;
  word-break: break-all;
}
.record-card .meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.record-card .actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

/* Inline edit */
.edit-form input,
.edit-form select {
  width: 100%;
  padding: 8px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
}
.edit-form .edit-actions { display: flex; gap: 8px; }

/* Search bar */
.search-bar {
  margin-bottom: 16px;
}
.search-bar input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Loading / empty states */
.loading, .empty {
  text-align: center;
  padding: 32px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pulsing border for barcode input */
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
  50% { box-shadow: 0 0 0 6px rgba(37,99,235,0.08); }
}
.barcode-ready { animation: pulse 2s ease-in-out infinite; }

/* Desktop tweaks */
@media (min-width: 768px) {
  .page { padding: 24px; }
  .barcode-input { font-size: 28px !important; }
}

/* Login page - centered */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card h2 {
  text-align: center;
  font-size: 22px;
  margin-bottom: 8px;
}
.login-card .subtitle {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}
