/* =============================================
   QR App - Free Online QR Code Generator
   Responsive styles, mobile-first
   ============================================= */

/* ---- Reset & Base ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  background: none;
  outline: none;
}

/* ---- Screen Reader Only ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

button:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

input, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ---- Header ---- */
.header {
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.logo-icon {
  font-size: 28px;
  color: #667eea;
  font-weight: 700;
}

.logo-text {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a2e;
  letter-spacing: -0.5px;
}

.tagline {
  font-size: 14px;
  color: #888;
  margin-left: auto;
}

/* ---- Layout ---- */
.app-layout {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 24px;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

/* ---- Form Panel ---- */
.form-panel {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  position: relative;
}

/* ---- Mode Tabs ---- */
.mode-tabs {
  display: flex;
  gap: 4px;
  background: #f0f2f5;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 24px;
}

.mode-tab {
  flex: 1;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #666;
  border-radius: 10px;
  transition: all 0.2s;
  text-align: center;
}

.mode-tab:hover {
  color: #333;
}

.mode-tab.active {
  background: #fff;
  color: #667eea;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ---- Mode Panels ---- */
.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

/* ---- Form Elements ---- */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.label-opt {
  font-weight: 400;
  color: #999;
  text-transform: none;
  letter-spacing: 0;
}

.form-textarea {
  width: 100%;
  padding: 12px 16px;
  font-size: 14px;
  color: #333;
  background: #fafafa;
  border: 2px solid #e8e8e8;
  border-radius: 10px;
  resize: vertical;
  transition: border-color 0.2s;
  line-height: 1.5;
}

.form-textarea:focus {
  border-color: #667eea;
  background: #fff;
  outline: none;
}

.form-textarea::placeholder {
  color: #bbb;
}

.batch-textarea {
  min-height: 180px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-half {
  flex: 1;
}

/* ---- Upload Area ---- */
.upload-area {
  width: 100%;
  height: 140px;
  background: #fafafa;
  border: 2px dashed #d0d0d0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}

.upload-area:hover {
  border-color: #667eea;
  background: #f8f7ff;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #bbb;
  pointer-events: none;
}

.upload-icon {
  font-size: 36px;
  line-height: 1;
  color: #ccc;
}

.upload-text {
  font-size: 13px;
  margin-top: 8px;
  color: #aaa;
}

.upload-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

/* ---- Color Swatches ---- */
.color-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
  flex-shrink: 0;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  border-color: #667eea;
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px #667eea;
}

/* ---- Option Tags (Error Level) ---- */
.option-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.option-tag {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  background: #f5f5f5;
  border: 2px solid #e8e8e8;
  border-radius: 8px;
  transition: all 0.15s;
}

.option-tag:hover {
  background: #eee;
}

.option-tag.active {
  color: #667eea;
  border-color: #667eea;
  background: #f0eeff;
}

/* ---- Buttons ---- */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 16px rgba(102,126,234,0.3);
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(102,126,234,0.35);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(102,126,234,0.25);
}

.btn-primary:disabled {
  background: #c0c4cc;
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.btn-sm {
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  transition: all 0.15s;
}

.btn-danger {
  color: #e74c3c;
  background: #fff5f5;
  border: 1px solid #f5c6cb;
}

.btn-danger:hover {
  background: #ffe8e8;
}

/* ---- Batch Results ---- */
.batch-results {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

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

.batch-count {
  font-size: 13px;
  color: #888;
  font-weight: 500;
}

.btn-save-all {
  color: #fff;
  background: linear-gradient(135deg, #43e97b, #38f9d7);
  border: none;
  box-shadow: 0 3px 10px rgba(67,233,123,0.25);
}

.btn-save-all:hover {
  box-shadow: 0 4px 14px rgba(67,233,123,0.35);
  transform: translateY(-1px);
}

.batch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  max-height: 500px;
  overflow-y: auto;
  padding: 4px;
}

.batch-item {
  background: #fafafa;
  border-radius: 12px;
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid #eee;
  transition: box-shadow 0.15s;
}

.batch-item:hover {
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}

.batch-item canvas {
  width: 120px;
  height: 120px;
  border-radius: 8px;
}

.batch-item-label {
  font-size: 11px;
  color: #888;
  margin: 8px 0 10px;
  text-align: center;
  word-break: break-all;
  max-width: 100%;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.batch-item .btn-sm {
  font-size: 12px;
  padding: 6px 16px;
  color: #fff;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 6px;
}

/* ---- Preview Panel ---- */
.preview-panel {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.preview-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-canvas-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

#qrCanvas {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  image-rendering: pixelated;
}

.preview-empty {
  text-align: center;
  padding: 60px 20px;
  color: #ccc;
}

.preview-empty .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.preview-empty p {
  font-size: 14px;
  line-height: 1.6;
}

.preview-info {
  width: 100%;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #999;
}

.info-content {
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Download Button ---- */
.btn-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(102,126,234,0.3);
  transition: all 0.2s;
}

.btn-download:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(102,126,234,0.35);
}

.btn-download:active:not(:disabled) {
  transform: translateY(0);
}

.btn-download:disabled {
  background: #d0d0d0;
  box-shadow: none;
  cursor: not-allowed;
  color: #aaa;
}

.download-icon {
  font-size: 20px;
  font-weight: 700;
}

/* ---- Hint ---- */
.hint {
  font-size: 13px;
  color: #888;
  line-height: 1.6;
  padding: 14px 16px;
  background: #fffbe6;
  border-radius: 10px;
  border: 1px solid #ffe58f;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: #333;
  color: #fff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: #e74c3c;
}

.toast.success {
  background: #27ae60;
}

/* ---- Footer ---- */
.footer {
  margin-top: auto;
  padding: 20px 24px;
  border-top: 1px solid #e8e8e8;
  background: #fff;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  font-size: 13px;
  color: #aaa;
  text-align: center;
}

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

@media (max-width: 820px) {
  .app-layout {
    grid-template-columns: 1fr;
    margin: 16px auto;
    padding: 0 16px;
  }

  .preview-panel {
    position: static;
  }

  .header {
    padding: 12px 16px;
  }

  .tagline {
    display: none;
  }

  .form-panel {
    padding: 20px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .preview-card {
    padding: 20px;
  }

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

@media (max-width: 480px) {
  .logo-text {
    font-size: 18px;
  }

  .mode-tabs {
    gap: 2px;
    padding: 3px;
  }

  .mode-tab {
    padding: 8px 10px;
    font-size: 13px;
  }

  .preview-card {
    padding: 16px;
  }

  .batch-item canvas {
    width: 100px;
    height: 100px;
  }
}
