:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --purple: #8b5cf6;
  --pink: #ec4899;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 8px;
  --radius-lg: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header h1 {
  font-size: 1.125rem;
  font-weight: 600;
  white-space: nowrap;
}

.header-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.875rem;
  font-weight: 400;
  opacity: 0.8;
  white-space: nowrap;
  display: none;
}

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

.feedback-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius);
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.feedback-btn:hover {
  background: rgba(255,255,255,0.25);
}

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

.main-content {
  padding: 16px;
  padding-bottom: 40px;
  max-width: 800px;
  margin: 0 auto;
}

.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--gray-800);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg {
  width: 20px;
  height: 20px;
  color: var(--primary);
  flex-shrink: 0;
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--gray-700);
}

.form-label .hint {
  font-weight: 400;
  color: var(--gray-400);
  font-size: 0.75rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

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

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-accent {
  background: var(--accent);
  color: white;
}

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

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #16a34a;
}

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background: var(--gray-300);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary-light);
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger-outline:hover {
  background: #fef2f2;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 8px;
  min-width: 36px;
  min-height: 36px;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-group .btn {
  flex: 1;
  min-width: 0;
}

/* QR Display */
.qr-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  background: var(--gray-50);
  border-radius: var(--radius-lg);
  border: 2px dashed var(--gray-200);
  min-height: 260px;
  justify-content: center;
  transition: border-color 0.3s;
}

.qr-display.has-qr {
  border-color: var(--primary);
  border-style: solid;
}

.qr-canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-canvas-wrap canvas,
.qr-canvas-wrap img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.qr-placeholder {
  text-align: center;
  color: var(--gray-400);
}

.qr-placeholder svg {
  width: 64px;
  height: 64px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.qr-placeholder p {
  font-size: 0.875rem;
}

.qr-info {
  margin-top: 16px;
  text-align: center;
  width: 100%;
}

.qr-info-type {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--primary-light);
  color: var(--primary);
  margin-bottom: 4px;
}

.qr-info-content {
  font-size: 0.8125rem;
  color: var(--gray-500);
  word-break: break-all;
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.qr-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  width: 100%;
  flex-wrap: wrap;
}

.qr-actions .btn {
  flex: 1;
  min-width: 80px;
}

/* Type-specific fields */
.type-fields {
  display: none;
}

.type-fields.active {
  display: block;
}

/* Collapsible section */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.collapsible-header:hover {
  color: var(--primary);
}

.collapsible-header svg {
  width: 18px;
  height: 18px;
  transition: transform 0.3s;
  color: var(--gray-400);
}

.collapsible-header.open svg {
  transform: rotate(180deg);
}

.collapsible-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 0;
}

.collapsible-body.open {
  max-height: 600px;
  opacity: 1;
}

.collapsible-body-inner {
  padding-top: 16px;
}

/* Color picker row */
.color-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-row input[type="color"] {
  width: 40px;
  height: 40px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: white;
  flex-shrink: 0;
}

.color-row input[type="color"]:hover {
  border-color: var(--primary);
}

.color-hex {
  font-size: 0.8125rem;
  color: var(--gray-500);
  font-family: monospace;
}

/* Size selector */
.size-options {
  display: flex;
  gap: 8px;
}

.size-option {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  background: white;
  font-size: 0.75rem;
  color: var(--gray-600);
}

.size-option:hover {
  border-color: var(--primary);
}

.size-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.size-option .size-label {
  display: block;
  font-weight: 500;
  font-size: 0.8125rem;
}

.size-option .size-dim {
  display: block;
  font-size: 0.6875rem;
  color: var(--gray-400);
  margin-top: 2px;
}

/* Error correction selector */
.ec-levels {
  display: flex;
  gap: 8px;
}

.ec-option {
  flex: 1;
  text-align: center;
  padding: 8px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}

.ec-option:hover {
  border-color: var(--primary);
}

.ec-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.ec-option .ec-label {
  display: block;
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--gray-700);
}

.ec-option.active .ec-label {
  color: var(--primary);
}

.ec-option .ec-desc {
  display: block;
  font-size: 0.6875rem;
  color: var(--gray-400);
  margin-top: 2px;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--gray-50);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.history-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.history-item-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--gray-200);
  overflow: hidden;
}

.history-item-thumb canvas,
.history-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.history-item-info {
  flex: 1;
  min-width: 0;
}

.history-item-type {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.history-item-text {
  font-size: 0.8125rem;
  color: var(--gray-600);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-time {
  font-size: 0.6875rem;
  color: var(--gray-400);
  margin-top: 2px;
}

.history-item-delete {
  padding: 6px;
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.history-item-delete:hover {
  color: var(--danger);
  background: #fef2f2;
}

.history-item-delete svg {
  width: 16px;
  height: 16px;
}

.history-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--gray-400);
  font-size: 0.875rem;
}

.history-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* Batch mode */
.batch-result {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.batch-item {
  background: var(--gray-50);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  border: 1px solid var(--gray-200);
}

.batch-item canvas {
  width: 120px;
  height: 120px;
  display: block;
  margin: 0 auto 8px;
}

.batch-item-label {
  font-size: 0.75rem;
  color: var(--gray-600);
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.batch-item .btn {
  font-size: 0.75rem;
  padding: 6px 12px;
}

/* Toast */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  z-index: 300;
  animation: fadeIn 0.3s ease-out;
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-500);
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--gray-800);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 12px;
}

/* Tabs */
.tab-bar {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 16px;
}

.tab-item {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  background: none;
}

.tab-item.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.tab-item:hover:not(.active) {
  color: var(--gray-700);
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

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

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.fade-in {
  animation: fadeIn 0.3s ease-out;
}

.scale-in {
  animation: scaleIn 0.3s ease-out;
}

/* Tab content */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--gray-500);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Responsive */
@media (min-width: 640px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .batch-result {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }

  .qr-actions .btn {
    flex: none;
  }
}

@media (min-width: 768px) {
  .main-content {
    padding: 24px;
    padding-bottom: 60px;
  }

  .header-center {
    display: block;
  }

  .card {
    padding: 24px;
  }
}

/* Input group */
.input-group {
  display: flex;
  gap: 0;
}

.input-group .form-select {
  width: auto;
  border-radius: var(--radius) 0 0 var(--radius);
  border-right: none;
  flex-shrink: 0;
  max-width: 100px;
}

.input-group .form-input {
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* Count badge */
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.6875rem;
  font-weight: 600;
}
