/* ============================================
   QR Code 生成器 — 樣式表
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --surface: #FFFFFF;
  --background: #F1F5F9;
  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --success: #10B981;
  --error: #EF4444;
  --error-light: #FEF2F2;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --transition: 0.2s ease;
}

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

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

body {
  font-family: var(--font-family);
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

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

.header-icon { color: var(--primary); flex-shrink: 0; }

.brand-logo {
  height: 32px;
  width: auto;
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* --- Main Layout --- */
.main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

.layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 24px;
  align-items: start;
}

/* --- Panel (Control) --- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* --- Form Controls --- */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.textarea, .input, .select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-family);
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--transition);
  outline: none;
}

.textarea:focus, .input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

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

.char-count {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* --- Range Slider --- */
.range {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  margin-top: 4px;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* --- Color Input --- */
.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-input {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  cursor: pointer;
  background: none;
}

.color-hex {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-family: monospace;
}

/* --- Toggle --- */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.toggle-label input { display: none; }

.toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.toggle-label input:checked + .toggle-track {
  background: var(--primary);
}

.toggle-label input:checked + .toggle-track::after {
  transform: translateX(18px);
}

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

.btn-sm { padding: 7px 14px; font-size: 0.8rem; }

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

.btn-secondary {
  background: var(--text-secondary);
  color: #fff;
}
.btn-secondary:hover { background: #475569; }

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

.btn-danger:hover { border-color: var(--error); color: var(--error); }

.download-btns {
  display: flex;
  gap: 8px;
}

.download-btns .btn { flex: 1; }

/* --- Logo Upload --- */
.logo-upload-area {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.url-input-row {
  display: flex;
  gap: 6px;
}

.url-input-row .input { flex: 1; }

.logo-preview-area {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.logo-preview-img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  background: #f8fafc;
}

/* --- Preset Logos --- */
.preset-logos {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 6px;
}

.preset-logo-btn {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  padding: 8px;
  transition: all var(--transition);
}

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

.preset-logo-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --- Radio Group --- */
.radio-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.radio-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all var(--transition);
  text-align: center;
}

.radio-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.radio-label input { display: none; }

/* --- Hint & Error --- */
.hint {
  font-size: 0.78rem;
  color: var(--primary);
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--primary-light);
  border-radius: var(--radius);
}

.url-hint-info {
  color: var(--primary);
  background: var(--primary-light);
}

.url-hint-error {
  color: var(--error);
  background: var(--error-light);
}

.error-msg {
  font-size: 0.78rem;
  color: var(--error);
  margin-top: 4px;
  min-height: 0;
}

.error-msg:not(:empty) {
  padding: 6px 10px;
  background: var(--error-light);
  border-radius: var(--radius);
  margin-top: 6px;
}

/* --- Preview Panel --- */
.preview-panel {
  position: sticky;
  top: 80px;
}

.preview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.preview-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.preview-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

.preview-body {
  padding: 32px;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: relative;
}

.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.qr-output {
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.preview-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.size-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- Spinner --- */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* --- Footer --- */
.footer {
  text-align: center;
  padding: 16px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ============================================
   Responsive
   ============================================ */

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
  .layout {
    grid-template-columns: 1fr 1fr;
  }
}

/* Mobile */
@media (max-width: 767px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
    order: -1;
  }

  .preview-body {
    min-height: 240px;
    padding: 20px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .main { padding: 16px; }

  .section { padding: 16px; }

  .radio-group {
    grid-template-columns: repeat(2, 1fr);
  }

  .preset-logos {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Small Mobile */
@media (max-width: 400px) {
  .download-btns {
    flex-direction: column;
  }
}
