* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #1f2937;
}

.app-header {
  text-align: center;
  padding: 32px 16px 16px;
  color: #fff;
}
.app-header h1 { margin: 0; font-size: 2rem; }
.app-header .subtitle { margin: 8px 0 0; opacity: 0.9; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}
.card h2 { margin: 0 0 16px; font-size: 1.25rem; color: #374151; }

.scanner-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #4338ca; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }
.btn-success { background: #10b981; color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.input, .select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.95rem;
  flex: 1;
  min-width: 0;
  background: #fff;
}
.input:focus, .select:focus { outline: 2px solid #4f46e5; outline-offset: 0; border-color: transparent; }

.form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}

.reader {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  min-height: 0;
}
.reader:empty { display: none; }

.last-scan {
  margin-top: 16px;
  padding: 12px;
  border: 2px solid #10b981;
  border-radius: 8px;
  background: #ecfdf5;
}
.last-scan h3 { margin: 0 0 8px; font-size: 1rem; color: #047857; }
.scan-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  word-break: break-all;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: #fff;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #d1fae5;
}

.badge {
  display: inline-block;
  background: #4f46e5;
  color: #fff;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: -apple-system, sans-serif;
}

.hidden { display: none !important; }
.muted { color: #6b7280; font-style: italic; }

.stats-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.stat-label { font-size: 0.85rem; color: #6b7280; }
.stat-value { font-size: 2rem; font-weight: 700; color: #4f46e5; }

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.list-header h2 { margin: 0; }

.qr-list {
  display: grid;
  gap: 8px;
  max-height: 500px;
  overflow-y: auto;
}

.qr-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
}
.qr-item-main { flex: 1; min-width: 0; }
.qr-item-content {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  word-break: break-all;
  margin-bottom: 4px;
}
.qr-item-meta {
  font-size: 0.8rem;
  color: #6b7280;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.qr-item-note {
  font-size: 0.85rem;
  color: #4b5563;
  margin-top: 4px;
  font-style: italic;
}

.app-footer {
  text-align: center;
  color: rgba(255,255,255,0.85);
  padding: 24px 16px 32px;
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #1f2937;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  z-index: 1000;
  animation: slideIn 0.2s ease-out;
}
.toast.success { background: #10b981; }
.toast.error { background: #ef4444; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

@media (max-width: 600px) {
  .app-header h1 { font-size: 1.5rem; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row .input, .form-row .btn { width: 100%; }
  .scanner-controls { flex-direction: column; }
  .scanner-controls .btn, .scanner-controls .select { width: 100%; }
}
