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

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #6366f1;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --transition: 150ms ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 24px;
}

.header {
  text-align: center;
  margin-bottom: 32px;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 14px;
  margin-bottom: 12px;
}

.header h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 400;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.config-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 160px);
}

.config-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.config-section {
  border-bottom: 1px solid var(--border);
}

.config-section:last-child {
  border-bottom: none;
}

.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 20px;
  font-size: 13px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  transition: background var(--transition);
}

.section-toggle:hover {
  background: var(--surface-hover);
}

.section-toggle .chevron {
  transition: transform 200ms ease;
  color: var(--text-muted);
}

.config-section.open .section-toggle .chevron {
  transform: rotate(180deg);
}

.section-body {
  display: none;
  padding: 0 20px 16px;
}

.config-section.open .section-body {
  display: block;
}

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

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

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

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

.form-row .form-group {
  margin-bottom: 0;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.label-hint {
  color: var(--text-muted);
  font-weight: 400;
}

textarea,
select,
input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: vertical;
}

textarea:focus,
select:focus,
input[type="text"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea::placeholder,
input[type="text"]::placeholder {
  color: var(--text-muted);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='10' viewBox='0 0 10 10' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2.5 3.5L5 6.5L7.5 3.5' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

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

input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border-radius: 3px;
  border: none;
}

.color-input-wrap input[type="text"] {
  width: 100%;
}

input[type="range"] {
  width: 100%;
  height: 5px;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
  transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

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

.shape-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.shape-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.shape-option input[type="radio"] {
  display: none;
}

.shape-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary);
}

.shape-preview {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shape-inner {
  display: block;
  background: var(--text);
}

.shape-square {
  width: 18px;
  height: 18px;
  border-radius: 2px;
}

.shape-rounded {
  width: 18px;
  height: 18px;
  border-radius: 5px;
}

.shape-circle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
}

.shape-diamond {
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  border-radius: 2px;
}

.shape-heart {
  width: 10px;
  height: 10px;
  background: none;
  position: relative;
}

.shape-heart::before,
.shape-heart::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 12px;
  background: var(--text);
  border-radius: 8px 8px 0 0;
}

.shape-heart::before {
  left: 1px;
  top: -2px;
  transform: rotate(-45deg);
  transform-origin: 0 100%;
}

.shape-heart::after {
  left: 9px;
  top: -2px;
  transform: rotate(45deg);
  transform-origin: 100% 100%;
}

.shape-rounded-ring {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 4px solid var(--text);
  background: transparent;
  box-sizing: border-box;
  position: relative;
}

.shape-rounded-ring::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: var(--text);
  border-radius: 2px;
}

.shape-circle-ring {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 4px solid var(--text);
  background: transparent;
  box-sizing: border-box;
  position: relative;
}

.shape-circle-ring::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: var(--text);
  border-radius: 50%;
}

.shape-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
}

.shape-option:has(input:checked) .shape-label {
  color: var(--primary);
}

.logo-upload-area {
  position: relative;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px;
  border: 2px dashed var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color var(--transition), background var(--transition);
}

.upload-placeholder:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.upload-placeholder span {
  font-size: 12px;
  font-weight: 500;
}

.upload-preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.upload-preview img {
  max-height: 64px;
  max-width: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.remove-logo {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.remove-logo:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.btn-remove-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  color: var(--danger);
  background: none;
  border: 1px solid var(--danger);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-remove-text:hover {
  background: var(--danger);
  color: white;
}

.form-actions {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-generate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: var(--surface);
  background: var(--primary);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform 100ms ease;
  box-shadow: 0 1px 2px rgba(99, 102, 241, 0.3);
}

.btn-generate:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.btn-generate:active {
  transform: scale(0.98);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 32px;
}

.qr-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  min-height: 420px;
  background: var(--bg);
  position: relative;
}

.qr-container canvas {
  max-width: 100%;
  max-height: 100%;
}

.preview-hint {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  color: var(--surface);
  background: var(--primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-download:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-download:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.footer p {
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .main-container {
    grid-template-columns: 1fr;
  }

  .config-panel {
    max-height: none;
  }

  .preview-panel {
    position: static;
  }

  .app {
    padding: 20px 16px;
  }

  .header {
    margin-bottom: 24px;
  }

  .header h1 {
    font-size: 22px;
  }

  .qr-container {
    min-height: 300px;
    padding: 20px;
  }

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

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

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}
