/* ── Design Tokens ─────────────────────────────────────────────────── */
:root {
  --color-brand: #1e293b;
  --color-brand-dark: #0f172a;
  --color-brand-light: #f1f5f9;
  --color-accent: #F20000;
  --color-accent-hover: #BC0000;
  --color-danger: #ef4444;
  --color-success: #22c55e;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-surface: #ffffff;
  --color-surface-alt: #f8fafc;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.12);
  --transition: .2s ease;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-brand-light);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--color-brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.logo-group {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.logo-text .brand {
  font-weight: 700;
  font-size: 18px;
  display: block;
  line-height: 1.1;
  color: #fff;
}
.logo-text .domain {
  font-size: 11px;
  opacity: .6;
  color: #fff;
}
.header-nav {
  display: flex;
  gap: 16px;
  align-items: center;
}
.header-nav a {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color var(--transition);
}
.header-nav a:hover { color: #fff; }

/* ── Footer ────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 20px 24px;
  font-size: 12px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  margin-top: auto;
}
.app-footer a {
  color: var(--color-accent);
  text-decoration: none;
}

/* ── Hero ──────────────────────────────────────────────────────────── */
.qr-hero {
  text-align: center;
  padding: 36px 24px 8px;
  max-width: 640px;
  margin: 0 auto;
}
.qr-hero h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.6px;
  color: var(--color-brand);
  margin-bottom: 8px;
}
.qr-hero h1 span {
  background: linear-gradient(135deg, #F20000, #BC0000);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.qr-hero p {
  font-size: 15px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ── Main Layout ───────────────────────────────────────────────────── */
.qr-app {
  display: flex;
  gap: 28px;
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 24px;
  width: 100%;
  flex: 1;
}
.panel-left {
  width: 420px;
  min-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 120px);
  padding-right: 4px;
}
.panel-left::-webkit-scrollbar { width: 5px; }
.panel-left::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
.panel-right {
  flex: 1;
  position: sticky;
  top: 80px;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ── Sections (collapsible) ────────────────────────────────────────── */
.section {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  overflow: hidden;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 14px;
  color: var(--color-brand);
  background: var(--color-surface-alt);
  border-bottom: 1px solid transparent;
  transition: background var(--transition);
}
.section-header:hover { background: var(--color-brand-light); }
.section-header .arrow {
  width: 18px;
  height: 18px;
  transition: transform .25s ease;
  opacity: .5;
}
.section.collapsed .section-header .arrow { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.section-header.active { border-bottom-color: var(--color-border); }
.section-body { padding: 16px; }

/* ── Data Type Tabs ────────────────────────────────────────────────── */
.data-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 0 12px;
  scrollbar-width: none;
  flex-wrap: wrap;
}
.data-tabs::-webkit-scrollbar { display: none; }
.data-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.data-tab:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.data-tab.active {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}

/* ── Form inputs ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 12px; }
.form-group:last-child { margin-bottom: 0; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(242,0,0,.12);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.form-row {
  display: flex;
  gap: 10px;
}
.form-row .form-group { flex: 1; }

/* ── QR Preview ────────────────────────────────────────────────────── */
.qr-preview-wrap {
  width: 100%;
  max-width: 500px;
}
.qr-preview {
  background: linear-gradient(145deg, #1a1a2e 0%, #0f172a 100%);
  border-radius: var(--radius-lg);
  padding: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
}
.qr-preview::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(145deg, rgba(255,255,255,0.1), transparent);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.qr-canvas {
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  max-width: 100%;
  height: auto;
}
.qr-info-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 0 4px;
  font-size: 12px;
  color: var(--color-text-muted);
}
.qr-info-bar .info-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-family: monospace;
  font-size: 11px;
}
.qr-info-bar .info-chip svg {
  width: 12px;
  height: 12px;
  opacity: 0.5;
}

/* ── Style Grid ────────────────────────────────────────────────────── */
.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}
.style-item {
  aspect-ratio: 1;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.style-item:hover { border-color: var(--color-accent); }
.style-item.active {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(242,0,0,.25);
}
.style-item canvas {
  width: 100%;
  height: 100%;
}
.style-label {
  font-size: 10px;
  color: var(--color-text-muted);
  text-align: center;
  margin-top: 4px;
}

/* ── Color pickers ─────────────────────────────────────────────────── */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.color-row:last-child { margin-bottom: 0; }
.color-picker-wrap {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--color-border);
  flex-shrink: 0;
}
.color-picker-wrap input[type="color"] {
  position: absolute;
  top: -4px; left: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  border: none;
  cursor: pointer;
  background: none;
}
.color-picker-wrap input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker-wrap input[type="color"]::-webkit-color-swatch { border: none; }
.color-label {
  font-size: 13px;
  color: var(--color-text);
  flex: 1;
}
.color-hex {
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: monospace;
  width: 72px;
  text-align: center;
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
}

/* ── Preset Cards ──────────────────────────────────────────────────── */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}
.preset-card {
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 6px;
  text-align: center;
  transition: all var(--transition);
  background: var(--color-surface);
}
.preset-card:hover { border-color: var(--color-accent); transform: translateY(-1px); }
.preset-card.active { border-color: var(--color-accent); }
.preset-card canvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
}
.preset-card .preset-name {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Logo Grid ─────────────────────────────────────────────────────── */
.logo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  margin-top: 10px;
}
.logo-item {
  aspect-ratio: 1;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  transition: all var(--transition);
  padding: 6px;
}
.logo-item:hover { border-color: var(--color-accent); }
.logo-item.active { border-color: var(--color-accent); box-shadow: 0 0 0 2px rgba(242,0,0,.2); }
.logo-item svg { width: 100%; height: 100%; }

/* ── Slider ────────────────────────────────────────────────────────── */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.slider-row:last-child { margin-bottom: 0; }
.slider-label { font-size: 13px; min-width: 90px; color: var(--color-text); }
.slider-value { font-size: 12px; color: var(--color-text-muted); min-width: 36px; text-align: right; font-family: monospace; }
input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--color-border);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

/* ── Toggle / Checkbox ─────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.toggle-label { font-size: 13px; flex: 1; }
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  border-radius: 11px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}
.toggle-switch input:checked + .toggle-track {
  background: var(--color-accent);
}
.toggle-switch 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-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-brand);
  color: #fff;
}
.btn-primary:hover { background: var(--color-brand-dark); }
.btn-accent {
  background: var(--color-accent);
  color: #fff;
}
.btn-accent:hover { background: var(--color-accent-hover); }
.btn-outline {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-outline:hover { border-color: var(--color-brand); background: var(--color-surface-alt); }

.download-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 500px;
}
.download-row .btn { flex: 1; min-width: 0; }
.download-row .btn-primary {
  background: linear-gradient(135deg, #1e293b, #334155);
  border: 1px solid rgba(255,255,255,0.05);
}
.download-row .btn-primary:hover {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.download-row .btn-outline:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ── Upload area ───────────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--color-text-muted);
  font-size: 13px;
}
.upload-area:hover { border-color: var(--color-accent); color: var(--color-accent); }

/* ── Color Presets ─────────────────────────────────────────────────── */
.color-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.color-preset {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid var(--color-border);
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
}
.color-preset:hover { transform: scale(1.1); }
.color-preset.active { border-color: var(--color-accent); box-shadow: 0 0 0 2px rgba(59,130,246,.3); }
.color-preset-fg,
.color-preset-bg {
  position: absolute;
  width: 100%;
  height: 50%;
  left: 0;
}
.color-preset-fg { top: 0; }
.color-preset-bg { bottom: 0; }

/* ── EC Level buttons ──────────────────────────────────────────────── */
.ec-group {
  display: flex;
  gap: 4px;
}
.ec-btn {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
}
.ec-btn:hover { border-color: var(--color-accent); }
.ec-btn.active {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .qr-app {
    flex-direction: column;
  }
  .panel-left {
    width: 100%;
    min-width: 0;
    max-height: none;
    overflow: visible;
  }
  .panel-right {
    position: static;
    width: 100%;
  }
  .qr-preview {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .qr-app { padding: 0 12px; margin: 12px auto; gap: 12px; }
  .section-body { padding: 12px; }
  .qr-preview { padding: 20px; min-height: 280px; }
  .download-row { flex-direction: column; }
  .download-row .btn { width: 100%; }
}
