/*
 * QR Code Generator — สไตล์ทั้งหมด (ไฟล์ต้นฉบับ)
 *
 * หลังแก้ไฟล์นี้ ให้สั่ง  node build.js  เพื่ออัปเดต qr-generator.html
 *
 * โทนสีอิงสไตล์ Facebook/Meta: น้ำเงิน #1877f2 บนพื้นเทาอ่อน การ์ดขาวมุมมน
 * เบรกพอยต์: 900px (สลับเป็นคอลัมน์เดียว) และ 520px (มือถือ)
 */

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-soft: #64748b;
  --line: #e2e8f0;
  --brand: #1877f2;
  --brand-dark: #145dbf;
  --brand-soft: #e7f0fe;
  --danger: #dc2626;
  --warn-bg: #fffbeb;
  --warn-ink: #92400e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

/* Author display rules would otherwise beat the UA rule for [hidden] */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 13px; }

/* The logo carries its own white card and border, so no background here */
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  flex: none;
}

.brand-mark svg { display: block; }

.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { margin: 1px 0 0; font-size: 13px; color: var(--ink-soft); }

.badge-offline {
  font-size: 12.5px;
  font-weight: 600;
  color: #166534;
  background: #dcfce7;
  padding: 6px 12px;
  border-radius: 999px;
}

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: 22px;
  max-width: 1180px;
  margin: 26px auto;
  padding: 0 22px 60px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.preview-panel { position: sticky; top: 24px; }

/* ------------------------------------------------------------------- steps */

.step { padding-bottom: 22px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.step:last-of-type { border-bottom: none; margin-bottom: 8px; }

.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }

.step-num {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 700;
  flex: none;
}

.step-head h2 { margin: 0; font-size: 15.5px; font-weight: 700; }
.optional { font-weight: 500; font-size: 13px; color: var(--ink-soft); }

/* ------------------------------------------------------------------ fields */

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }

.counter { float: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.counter.full { color: var(--warn-ink); }

input[type="text"], select {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input[type="text"]:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

#urlInput { font-size: 15px; }

.hint { margin: 6px 2px 0; font-size: 12.5px; color: var(--ink-soft); }
.hint.bad { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.quick-types { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  font: inherit;
  font-size: 13px;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  transition: .15s;
}
.chip:hover { border-color: var(--brand); color: var(--brand-dark); background: var(--brand-soft); }

/* colors */

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

input[type="color"] {
  width: 46px; height: 42px;
  padding: 3px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  flex: none;
}

.color-field input[type="text"] { text-transform: uppercase; font-size: 14px; }

/* switch */

.toggle-row { display: flex; align-items: center; gap: 11px; font-size: 14.5px; }

.switch { position: relative; display: inline-block; width: 44px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute; inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: .18s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 19px; height: 19px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .18s;
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(19px); }

.sub-panel {
  margin-top: 16px;
  padding: 16px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
}

/* dropzone */

.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  background: #fff;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }

.drop-empty { display: grid; justify-items: center; gap: 4px; color: var(--ink-soft); }
.drop-empty strong { color: var(--brand-dark); font-size: 14px; }
.drop-empty span { font-size: 12.5px; }

.drop-filled { display: flex; align-items: center; gap: 14px; text-align: left; }
.drop-filled img {
  width: 54px; height: 54px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  padding: 4px;
  flex: none;
}
.drop-meta { min-width: 0; }
.drop-meta strong { display: block; font-size: 13.5px; word-break: break-all; }

.link-danger {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 12.5px;
  color: var(--danger);
  cursor: pointer;
  text-decoration: underline;
}

/* range */

.range-field { margin-top: 16px; }
.range-field label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.range-field output { color: var(--brand-dark); }

input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
  cursor: pointer;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 14px;
  font-size: 13.5px;
  color: var(--ink-soft);
  cursor: pointer;
}
.check-row input { margin-top: 3px; accent-color: var(--brand); flex: none; }

.warn {
  margin: 14px 0 0;
  padding: 10px 12px;
  font-size: 12.5px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 9px;
  border: 1px solid #fde68a;
}

.err {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 9px;
}

/* ----------------------------------------------------------------- buttons */

.btn-primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 13px;
  font: inherit;
  font-size: 15.5px;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: 11px;
  cursor: pointer;
  transition: .15s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:active { transform: translateY(1px); }

/* ----------------------------------------------------------------- preview */

.preview-title { margin: 0 0 16px; font-size: 15.5px; font-weight: 700; }

.preview-stage {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: 20px;
  background: repeating-conic-gradient(#f8fafc 0 25%, #fff 0 50%) 50%/18px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.placeholder { display: grid; justify-items: center; gap: 10px; color: #94a3b8; text-align: center; }
.placeholder p { margin: 0; font-size: 13.5px; }

#qrCanvas {
  width: 100%;
  max-width: 320px;
  height: auto;
  border-radius: 8px;
  image-rendering: -webkit-optimize-contrast;
}

.result-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.result-meta > div {
  padding: 9px 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.result-meta span { display: block; font-size: 11.5px; color: var(--ink-soft); }
.result-meta strong { font-size: 14px; }

.download-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

.btn-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--brand);
  border: 1.5px solid var(--brand);
  border-radius: 10px;
  cursor: pointer;
  transition: .15s;
}
.btn-download:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-download.secondary { background: #fff; color: var(--brand-dark); border-color: var(--line); }
.btn-download.secondary:hover { background: var(--brand-soft); border-color: var(--brand); }

#dlPng { grid-column: 1 / -1; }

.toast {
  margin: 12px 0 0;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  background: #dcfce7;
  color: #166534;
  border-radius: 9px;
}

.toast.bad {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.note {
  margin-top: 18px;
  padding: 13px 15px;
  font-size: 12.8px;
  line-height: 1.65;
  color: var(--ink-soft);
  background: #f8fafc;
  border-left: 3px solid var(--brand);
  border-radius: 0 9px 9px 0;
}
.note strong { display: block; color: var(--ink); margin-bottom: 3px; font-size: 13.2px; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
}

@media (max-width: 520px) {
  .topbar { padding: 14px 18px; }
  .layout { padding: 0 14px 40px; margin-top: 18px; }
  .panel { padding: 18px; }
  .grid-2, .result-meta, .download-row { grid-template-columns: 1fr; }
}
