/* ==========================================================================
   QR Code Studio Pro - World-Class UI/UX & Multi-Theme Design System
   ========================================================================== */

:root {
  /* Color System Default */
  --bg-dark: #0b0f17;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-solid: #111827;
  --bg-card-hover: rgba(31, 41, 55, 0.8);
  --bg-input: rgba(15, 23, 42, 0.7);
  --bg-input-focus: rgba(15, 23, 42, 0.95);
  
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.12);
  --border-focus: #6366f1;

  --accent-primary: #6366f1;       /* Indigo */
  --accent-primary-glow: rgba(99, 102, 241, 0.3);
  --accent-secondary: #a855f7;     /* Violet */
  --accent-cyan: #06b6d4;          /* Cyan */
  --accent-promptpay: #00427A;     /* PromptPay Official Blue */
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.2);
  --shadow-card: 0 20px 40px -15px rgba(0, 0, 0, 0.6);
  --shadow-preview: 0 25px 50px -12px rgba(0, 0, 0, 0.5);

  --glass-blur: blur(20px);
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Mode Variables */
[data-theme="light"] {
  --bg-dark: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-solid: #ffffff;
  --bg-card-hover: rgba(241, 245, 249, 0.9);
  --bg-input: #ffffff;
  --bg-input-focus: #ffffff;

  --border-glass: rgba(0, 0, 0, 0.08);
  --border-subtle: rgba(0, 0, 0, 0.12);

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.12);
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.08);
}

/* Sunset Theme */
[data-theme="sunset"] {
  --bg-dark: #1a0b18;
  --bg-card: rgba(38, 17, 36, 0.8);
  --bg-card-solid: #261124;
  --accent-primary: #f97316;
  --accent-secondary: #ec4899;
  --border-focus: #f97316;
  --shadow-glow: 0 0 30px rgba(249, 115, 22, 0.3);
}

/* Midnight Theme */
[data-theme="midnight"] {
  --bg-dark: #0f0b1e;
  --bg-card: rgba(25, 18, 48, 0.8);
  --bg-card-solid: #191230;
  --accent-primary: #8b5cf6;
  --accent-secondary: #d946ef;
  --border-focus: #8b5cf6;
  --shadow-glow: 0 0 30px rgba(139, 92, 246, 0.3);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-family: 'Plus Jakarta Sans', 'Prompt', -apple-system, BlinkMacSystemFont, sans-serif;
  color-scheme: dark;
  scroll-behavior: smooth;
  font-size: 16px;
  width: 100%;
  overflow-x: hidden;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  width: 100%;
  line-height: 1.6;
  background-image: 
    radial-gradient(circle at 10% 10%, rgba(99, 102, 241, 0.14) 0%, transparent 45%),
    radial-gradient(circle at 90% 90%, rgba(6, 182, 212, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 50% 30%, rgba(168, 85, 247, 0.06) 0%, transparent 65%);
  background-attachment: fixed;
  overflow-x: hidden;
  position: relative;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Header */
.app-header {
  border-bottom: 1px solid var(--border-glass);
  background: rgba(11, 15, 23, 0.85);
  backdrop-filter: var(--glass-blur);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.85rem 1.5rem;
  width: 100%;
}

.header-container {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-main);
  text-decoration: none;
}

.brand-icon-wrapper {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-primary));
  color: #fff;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.06em;
  margin-left: 0.4rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.lang-btn {
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  font-weight: 800;
  font-size: 0.825rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: var(--transition-fast);
}

.lang-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
}

/* Main Layout Grid */
.main-wrapper {
  max-width: 1320px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
  box-sizing: border-box;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1.5rem;
  align-items: start;
  width: 100%;
}

/* Glass Panels */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Category Selector */
.type-selector-wrapper {
  position: relative;
  margin-bottom: 1.5rem;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.type-selector {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.25rem 0 0.75rem 0;
  width: 100%;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  -webkit-overflow-scrolling: touch;
}

.type-selector::-webkit-scrollbar {
  height: 4px;
}

.type-selector::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.type-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1.1rem;
  border-radius: 30px;
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: var(--transition-fast);
  user-select: none;
}

.type-tab:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-subtle);
  transform: translateY(-1px);
}

.type-tab.active {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-color: transparent;
  color: #ffffff;
  box-shadow: var(--shadow-glow);
  font-weight: 700;
}

.type-tab[data-type="promptpay"].active {
  background: linear-gradient(135deg, #00427A, var(--accent-cyan));
  box-shadow: 0 0 25px rgba(6, 182, 212, 0.3);
}

/* Main Section Switcher */
.section-tabs {
  display: flex;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  margin-bottom: 1.5rem;
  width: 100%;
}

.section-tab-btn {
  flex: 1;
  padding: 0.65rem 1rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition-fast);
}

.section-tab-btn:hover {
  color: var(--text-main);
}

.section-tab-btn.active {
  background: var(--bg-card-solid);
  color: var(--text-main);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Form Controls */
.form-group {
  margin-bottom: 1.25rem;
  width: 100%;
}

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  transition: var(--transition-fast);
  outline: none;
  box-sizing: border-box;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  background: var(--bg-input-focus);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 4px var(--accent-primary-glow);
}

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

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  width: 100%;
}

/* Customizer Section Cards */
.custom-card {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  width: 100%;
  box-sizing: border-box;
}

.custom-card-title {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

/* Presets Grid */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.6rem;
  width: 100%;
}

.preset-chip {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  transition: var(--transition-fast);
}

.preset-chip:hover, .preset-chip.active {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  background: var(--bg-card-hover);
}

.preset-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Pattern Options Grid */
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  width: 100%;
}

.pattern-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.pattern-card {
  padding: 0.65rem 0.4rem;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  text-align: center;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: var(--transition-fast);
}

.pattern-option input:checked + .pattern-card {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.18);
  color: var(--text-main);
}

/* Logo Preset Buttons Grid */
.logo-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
  width: 100%;
}

.logo-preset-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
  color: var(--text-main);
}

.logo-preset-btn:hover, .logo-preset-btn.active {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.2);
}

/* Color Pickers */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.color-input-custom {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  background: transparent;
  cursor: pointer;
  padding: 2px;
}

.color-input-custom::-webkit-color-swatch-wrapper {
  padding: 0;
}
.color-input-custom::-webkit-color-swatch {
  border: none;
  border-radius: 8px;
}

/* Right Sticky Preview Box */
.preview-column {
  position: sticky;
  top: 90px;
  width: 100%;
  min-width: 0;
}

.preview-box {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 1.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: var(--shadow-preview);
  text-align: center;
  width: 100%;
  box-sizing: border-box;
}

/* QR CANVAS CONTAINER */
.qr-canvas-container {
  width: 270px;
  height: 270px;
  max-width: 100%;
  background: #ffffff;
  border-radius: 22px;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  margin: 1rem 0 1.25rem 0;
}

#qr-canvas {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

#qr-canvas canvas, #qr-canvas svg {
  max-width: 100% !important;
  max-height: 100% !important;
  width: auto !important;
  height: auto !important;
  display: block !important;
  margin: 0 auto !important;
  object-fit: contain;
}

/* QR LOADING SPINNER */
.qr-loading-spinner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(6px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  color: var(--accent-primary);
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 20;
}

.qr-loading-spinner.active {
  display: flex !important;
}

.preview-info {
  margin: 0.5rem 0 1.25rem 0;
  width: 100%;
  overflow: hidden;
}

.preview-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.preview-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
  max-width: 100%;
  margin-top: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: var(--transition-normal);
  text-decoration: none;
  min-height: 42px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-subtle);
}

.btn-full {
  width: 100%;
}

.btn-group-row {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}

.download-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.export-opts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
}

/* Mobile Quick Floating Preview Bar */
.mobile-preview-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--border-glass);
  padding: 0.75rem 1.25rem;
  z-index: 99;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}

/* Modals */
dialog.modal {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  color: var(--text-main);
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  box-shadow: var(--shadow-card);
  margin: auto;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
}

/* Breakpoints */
@media (max-width: 1100px) {
  .app-grid {
    grid-template-columns: 1fr;
  }

  .preview-column {
    position: relative;
    top: 0;
    width: 100%;
  }

  .preview-box {
    max-width: 600px;
    margin: 0 auto;
  }
}

@media (max-width: 768px) {
  .main-wrapper {
    padding: 0 0.85rem;
    margin: 1rem auto;
  }

  .glass-panel {
    padding: 1.15rem;
    border-radius: var(--radius-lg);
  }

  .qr-canvas-container {
    width: 230px;
    height: 230px;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }

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

  .form-input, .form-select, .form-textarea {
    font-size: 16px;
  }

  .hide-mobile {
    display: none;
  }

  .brand-badge {
    display: none;
  }
}
