/* ============================================
   QR Code Generator — Main styles
   Responsive, accessible, dark mode support
   ============================================ */

:root {
  /* Light theme */
  --bg: #f0f2f8;
  --bg-gradient-start: #e8ecf7;
  --bg-gradient-end: #f5f7fc;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --text: #1a1a2e;
  --text-muted: #5c5c7a;
  --border: #dde1ec;
  --primary: #5b21b6;
  --primary-hover: #6d28d9;
  --primary-light: #ede9fe;
  --accent: #7c3aed;
  --error: #dc2626;
  --success: #059669;
  --shadow: 0 2px 12px rgba(91, 33, 182, 0.08);
  --shadow-lg: 0 12px 40px rgba(91, 33, 182, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  --bg: #0c0a14;
  --bg-gradient-start: #0f0d18;
  --bg-gradient-end: #14111f;
  --surface: #1a1625;
  --surface-elevated: #221d2e;
  --text: #f5f3f7;
  --text-muted: #a8a3b3;
  --border: #2d2838;
  --primary: #a78bfa;
  --primary-hover: #c4b5fd;
  --primary-light: #2e1065;
  --accent: #c4b5fd;
  --error: #f87171;
  --success: #34d399;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 50%, var(--bg) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Focus for accessibility */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Skip link (optional, for screen readers) */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  padding: 12px 16px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  z-index: 100;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 16px;
}

/* Layout */
.app-wrapper {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 56px;
}

/* Header */
.header {
  margin-bottom: 36px;
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.header-brand {
  flex: 1;
  min-width: 0;
}
.logo {
  font-size: 1.85rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.03em;
  color: var(--text);
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
[data-theme="dark"] .logo {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 420px;
}
.header-credits {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
}
.credits-by {
  color: var(--text-muted);
}
.credits-by strong {
  color: var(--text);
  font-weight: 600;
}
.credits-links {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.credits-sep {
  color: var(--border);
  font-weight: 300;
  user-select: none;
}
.credits-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.credits-link:hover {
  color: var(--primary-hover);
  border-bottom-color: var(--primary);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn:not(:disabled):active {
  transform: scale(0.98);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
  box-shadow: 0 2px 10px rgba(91, 33, 182, 0.3);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover) 0%, var(--accent) 100%);
  box-shadow: 0 4px 16px rgba(91, 33, 182, 0.35);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.btn-icon:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.btn-icon .icon-moon { display: none; }
[data-theme="dark"] .btn-icon .icon-sun { display: none; }
[data-theme="dark"] .btn-icon .icon-moon { display: inline; }
.btn-small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.card:hover {
  box-shadow: var(--shadow-lg);
}
.section-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 20px;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* Input section */
.section-input {
  margin-bottom: 24px;
}
.content-type-label {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 0 0 12px;
}
.content-type-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 22px;
}
.content-type-btn {
  padding: 10px 18px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.1s;
}
.content-type-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.content-type-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(91, 33, 182, 0.25);
}
[data-theme="dark"] .content-type-btn.active {
  box-shadow: 0 2px 12px rgba(167, 139, 250, 0.2);
}
.content-panel {
  margin-bottom: 16px;
}
.content-panel[hidden] {
  display: none;
}
.content-panel label {
  display: block;
  font-weight: 500;
  font-size: 0.9rem;
  margin: 12px 0 6px;
  color: var(--text);
}
.content-panel label:first-child {
  margin-top: 0;
}
.content-panel input[type="text"],
.content-panel input[type="url"],
.content-panel input[type="tel"],
.content-panel input[type="email"],
.content-panel input[type="datetime-local"],
.content-panel select,
.content-panel textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.content-panel input:focus,
.content-panel select:focus,
.content-panel textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  outline: none;
}
.content-panel textarea {
  resize: vertical;
  min-height: 60px;
}
.content-panel .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}
.input-group {
  position: relative;
}
.input-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text);
}
.input-group textarea {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font);
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s;
}
.input-group textarea::placeholder {
  color: var(--text-muted);
}
.input-group textarea:focus {
  border-color: var(--primary);
}
.char-count {
  position: absolute;
  right: 12px;
  bottom: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.error-message {
  color: var(--error);
  font-size: 0.9rem;
  margin: 8px 0 0;
}
.btn-generate {
  margin-top: 20px;
  padding: 14px 28px;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  width: 100%;
  max-width: 280px;
}

/* Two-column layout */
.layout-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout-two {
    grid-template-columns: 1fr;
  }
}

/* Customize panel */
.panel-customize .fieldset {
  border: none;
  margin: 0 0 24px;
  padding: 0;
}
.panel-customize legend {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--text);
}
.panel-customize .row {
  margin-bottom: 14px;
}
.panel-customize .row:last-child {
  margin-bottom: 0;
}
.panel-customize label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--text);
}
.panel-customize input[type="text"],
.panel-customize input[type="number"],
.panel-customize select {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.panel-customize input:focus,
.panel-customize select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  outline: none;
}
.panel-customize input[type="number"] {
  max-width: 120px;
}
.panel-customize input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.2s;
}
.panel-customize input[type="color"]:focus {
  border-color: var(--primary);
  outline: none;
}
.panel-customize .color-text {
  margin-left: 10px;
  width: calc(100% - 60px);
  max-width: 140px;
  display: inline-block;
  vertical-align: middle;
}
.panel-customize .checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.panel-customize .checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}
.panel-customize .checkbox-row label {
  margin: 0;
}
.panel-customize .hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.panel-customize .gradient-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.panel-customize .gradient-controls label {
  margin: 0;
}
.panel-customize .gradient-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.panel-customize input[type="file"] {
  font-size: 0.9rem;
  color: var(--text);
}

/* Preview panel */
.panel-preview {
  position: sticky;
  top: 24px;
}
.preview-wrap {
  background: linear-gradient(145deg, var(--bg) 0%, var(--surface) 100%);
  border-radius: var(--radius);
  padding: 28px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}
.qr-container {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}
.qr-container canvas,
.qr-container svg {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}
.preview-label {
  margin: 16px 0 0;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 280px;
  word-break: break-word;
}
.preview-empty {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
  text-align: center;
  line-height: 1.5;
}
.export-section {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  margin-top: 4px;
}
.export-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.export-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.export-message {
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--success);
}

/* Footer */
.footer {
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}
.footer-app {
  margin: 0 0 16px;
}
.footer-credits {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.footer-by {
  margin: 0 0 12px;
  color: var(--text-muted);
}
.footer-by strong {
  color: var(--text);
  font-weight: 600;
}
.footer-handle {
  color: var(--primary);
  font-weight: 500;
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
}
.footer-sep {
  color: var(--border);
  font-weight: 300;
  user-select: none;
}
.footer-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.footer-link:hover {
  color: var(--primary-hover);
  border-bottom-color: var(--primary);
}

/* Mobile */
@media (max-width: 600px) {
  .app-wrapper {
    padding: 20px 16px 40px;
  }
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .logo {
    font-size: 1.6rem;
  }
  .header-credits {
    margin-top: 10px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .credits-links {
    gap: 6px;
  }
  .credits-sep {
    display: none;
  }
  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .card {
    padding: 22px;
  }
  .section-input .card {
    padding: 22px;
  }
  .content-type-tabs {
    gap: 8px;
  }
  .content-type-btn {
    padding: 8px 14px;
    font-size: 0.8rem;
  }
  .btn-generate {
    max-width: none;
  }
  .export-buttons {
    flex-direction: column;
  }
  .export-buttons .btn {
    width: 100%;
  }
  .footer-links {
    flex-direction: column;
    gap: 8px;
  }
  .footer-sep {
    display: none;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
