/* ================================================================
   QR Kub — Design System
   ระบบดีไซน์ชุดเดียวที่ทุกหน้าใช้ร่วมกัน
   index.html · privacy.html · dashboard.php · tools/*
   ================================================================ */

/* ── Tokens ─────────────────────────────────────────────────── */
:root {
  color-scheme: light;

  --bg:            #ffffff;
  --bg-subtle:     #f7f8fa;
  --bg-inset:      #f1f2f5;
  --bg-hover:      #eceef2;

  --text:          #16181d;
  --text-muted:    #5b6270;
  --text-faint:    #6e747f;  /* 4.7:1 บนพื้นขาว ผ่านเกณฑ์อ่านง่ายขั้นต่ำ */

  --border:        #e3e5ea;
  --border-strong: #cdd1d9;

  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --accent-subtle: #eef2ff;
  --accent-border: #c7d0fd;
  --on-accent:     #ffffff;

  --danger:        #d92d20;
  --danger-subtle: #fef3f2;
  --danger-border: #fecdca;
  --success:       #067647;
  --success-subtle:#ecfdf3;
  --success-border:#abefc6;
  --warn:          #b54708;
  --warn-subtle:   #fffaeb;
  --warn-border:   #fedf89;

  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
  --radius-pill: 999px;

  --shadow-sm:  0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md:  0 4px 12px rgba(16, 24, 40, .08);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, .14);

  --ring:       0 0 0 3px rgba(79, 70, 229, .30);

  --header-h:   60px;
  --page-max:   1120px;

  --ease:       .18s cubic-bezier(.4, 0, .2, 1);

  --font: 'Inter', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #16181d;
  --bg-subtle:     #0f1115;
  --bg-inset:      #1e2128;
  --bg-hover:      #262a33;

  --text:          #f2f4f7;
  --text-muted:    #a2abba;
  --text-faint:    #79828f;

  --border:        #2a2e37;
  --border-strong: #3a3f4a;

  --accent:        #8b83ff;
  --accent-hover:  #a49dff;
  --accent-subtle: #1e1b39;
  --accent-border: #3d367a;
  --on-accent:     #12101f;

  --danger:        #ff8a80;
  --danger-subtle: #2a1614;
  --danger-border: #55231f;
  --success:       #6ee7b7;
  --success-subtle:#0d2820;
  --success-border:#1c4c3b;
  --warn:          #fcd34d;
  --warn-subtle:   #2a2110;
  --warn-border:   #56421a;

  --shadow-sm:  0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, .45);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, .6);

  --ring:       0 0 0 3px rgba(139, 131, 255, .35);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 12px);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-subtle);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.3; letter-spacing: -.015em; font-weight: 700; }
h1 { font-size: clamp(1.55rem, 3.4vw, 2.1rem); }
h2 { font-size: clamp(1.25rem, 2.4vw, 1.6rem); }
h3 { font-size: 1.05rem; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection { background: var(--accent-subtle); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid var(--bg-subtle); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ── Layout ─────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: 20px;
}
.container-narrow { max-width: 820px; }

.section { padding: 56px 0; }
.section-tight { padding: 36px 0; }
.section-alt { background: var(--bg); border-block: 1px solid var(--border); }

.section-head { margin-bottom: 28px; max-width: 640px; }
.section-head-center { margin-inline: auto; text-align: center; }
.section-title { margin-bottom: 8px; }
.section-sub { color: var(--text-muted); font-size: .95rem; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-end { margin-left: auto; }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex-shrink: 0; }
.brand-accent { color: var(--accent); }

.nav { display: flex; align-items: center; gap: 4px; }
.nav-link {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding-inline: 11px;
  border-radius: var(--radius-sm);
  font-size: .89rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--ease), background var(--ease);
}
.nav-link:hover { color: var(--text); background: var(--bg-inset); text-decoration: none; }
.nav-link[aria-current="page"] { color: var(--accent); background: var(--accent-subtle); }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  transition: var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--bg-inset); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }

.burger { display: none; }

/* เมนูมือถือ */
.mobile-menu {
  display: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 20px 14px;
}
.mobile-menu.open { display: block; }
.mobile-menu a {
  display: block;
  padding: 12px 4px;
  min-height: 44px;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.mobile-menu a:last-child { border-bottom: none; }

@media (max-width: 860px) {
  .nav { display: none; }
  .burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--text);
  }
  .burger svg { width: 20px; height: 20px; }
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: .93rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--ease), border-color var(--ease), color var(--ease), opacity var(--ease);
}
.btn:hover { background: var(--bg-inset); border-color: var(--border-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; flex-shrink: 0; }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-inset); border-color: transparent; color: var(--text); }

.btn-danger { color: var(--danger); border-color: var(--danger-border); background: var(--danger-subtle); }
.btn-danger:hover { background: var(--danger-subtle); border-color: var(--danger); }

.btn-sm { min-height: 36px; padding: 0 12px; font-size: .84rem; border-radius: var(--radius-sm); }
.btn-lg { min-height: 50px; padding: 0 24px; font-size: 1rem; }
.btn-block { width: 100%; }

/* ปุ่มที่กำลังทำงานอยู่ ใช้ร่วมกับ aria-busy */
.btn[aria-busy="true"] { pointer-events: none; opacity: .7; }
.btn[aria-busy="true"] .btn-label::after {
  content: '';
  display: inline-block;
  width: 13px; height: 13px;
  margin-left: 8px;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
}
.card-sm { padding: 16px; border-radius: var(--radius); }
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.card-title { font-size: 1rem; font-weight: 700; }

/* ── Form ───────────────────────────────────────────────────── */
.field { display: block; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  margin-bottom: 6px;
  font-size: .84rem;
  font-weight: 600;
  color: var(--text);
}
.label-optional { color: var(--text-faint); font-weight: 500; }

.hint { margin-top: 6px; font-size: .8rem; line-height: 1.55; color: var(--text-muted); }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: .95rem;
  color: var(--text);
  transition: border-color var(--ease), box-shadow var(--ease);
  appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.textarea { min-height: 108px; resize: vertical; line-height: 1.6; }
.select {
  cursor: pointer;
  padding-right: 38px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%235b6270' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23a2abba' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
}

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

/* แถบเลื่อน ให้พื้นที่จับกว้างพอสำหรับนิ้ว */
input[type="range"] {
  width: 100%;
  height: 32px;
  padding: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
  appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
}
input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 22px; height: 22px;
  margin-top: -8.5px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--shadow-sm);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--ring); }

/* ตัวเลือกสี */
.color-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 5px 12px 5px 5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
}
.color-field input[type="color"] {
  width: 34px; height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.color-field input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.color-value { font-family: var(--mono); font-size: .8rem; color: var(--text-muted); text-transform: uppercase; }

/* ── Segmented control ──────────────────────────────────────── */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--bg-inset);
  border-radius: var(--radius);
}
.seg-item {
  min-height: 38px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: .84rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: var(--ease);
}
.seg-item:hover { color: var(--text); }
.seg-item.active { background: var(--bg); color: var(--accent); box-shadow: var(--shadow-sm); }

/* ── Chip ───────────────────────────────────────────────────── */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  font-size: .86rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--ease);
}
.chip:hover { color: var(--text); background: var(--bg-inset); border-color: var(--border-strong); text-decoration: none; }
.chip.active { background: var(--accent-subtle); border-color: var(--accent-border); color: var(--accent); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: .74rem;
  font-weight: 600;
  background: var(--bg-inset);
  color: var(--text-muted);
}
.badge-accent { background: var(--accent-subtle); color: var(--accent); }
.badge-success { background: var(--success-subtle); color: var(--success); }

/* ── Swatches ───────────────────────────────────────────────── */
.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  padding: 0;
  position: relative;
  transition: var(--ease);
}
.swatch:hover { transform: scale(1.06); }
.swatch.active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.swatch-inner { position: absolute; inset: 5px; border-radius: 5px; }

/* ── Alert ──────────────────────────────────────────────────── */
.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-inset);
  font-size: .87rem;
  line-height: 1.6;
  color: var(--text-muted);
}
.alert strong { color: var(--text); }
.alert-error   { background: var(--danger-subtle);  border-color: var(--danger-border);  color: var(--danger); }
.alert-warn    { background: var(--warn-subtle);    border-color: var(--warn-border);    color: var(--warn); }
.alert-success { background: var(--success-subtle); border-color: var(--success-border); color: var(--success); }
.alert-info    { background: var(--accent-subtle);  border-color: var(--accent-border);  color: var(--accent); }
.alert-error strong, .alert-warn strong, .alert-success strong, .alert-info strong { color: inherit; }

/* ── Table ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
  background: var(--bg-inset);
  font-weight: 600;
  font-size: .8rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-subtle); }

/* ── Empty state ────────────────────────────────────────────── */
.empty { text-align: center; padding: 44px 20px; }
.empty-icon { color: var(--text-faint); margin: 0 auto 12px; }
.empty-title { font-weight: 600; margin-bottom: 6px; }
.empty-text { color: var(--text-muted); font-size: .89rem; margin-bottom: 18px; }

/* ── Skeleton ───────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-inset) 25%, var(--bg-hover) 37%, var(--bg-inset) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: var(--radius);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ── Accordion (FAQ) ────────────────────────────────────────── */
.accordion { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); overflow: hidden; }
.accordion + .accordion { margin-top: 10px; }
.accordion summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: .93rem;
  cursor: pointer;
  list-style: none;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after {
  content: '';
  width: 9px; height: 9px;
  margin-left: auto;
  flex-shrink: 0;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform var(--ease);
}
.accordion[open] summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.accordion summary:hover { background: var(--bg-subtle); }
.accordion-body { padding: 0 16px 16px; color: var(--text-muted); font-size: .9rem; line-height: 1.75; }

/* ── Disclosure (ปรับแต่งรูปแบบ) ────────────────────────────── */
.disclosure { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.disclosure > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  font-size: .89rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  color: var(--text);
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after {
  content: '';
  width: 8px; height: 8px;
  margin-left: auto;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform var(--ease);
}
.disclosure[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.disclosure-body { padding: 4px 14px 16px; border-top: 1px solid var(--border); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(16, 24, 40, .5);
  backdrop-filter: blur(3px);
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.modal-lg { max-width: 860px; }
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 900;
  max-width: min(440px, calc(100vw - 32px));
  padding: 13px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: .89rem;
  box-shadow: var(--shadow-pop);
  transform: translate(-50%, 16px);
  opacity: 0;
  transition: transform .22s ease, opacity .22s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ── Dropdown menu ──────────────────────────────────────────── */
.menu-wrap { position: relative; }
.menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: .86rem;
  font-weight: 500;
  transition: var(--ease);
}
.menu-trigger:hover { background: var(--bg-inset); border-color: var(--border-strong); }
.avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 230px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  z-index: 300;
}
.menu-head { padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-name { font-size: .88rem; font-weight: 600; }
.menu-mail { font-size: .78rem; color: var(--text-muted); word-break: break-all; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: .87rem;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  transition: background var(--ease);
}
.menu-item:hover { background: var(--bg-inset); text-decoration: none; }
.menu-item svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.menu-item-danger { color: var(--danger); }
.menu-item-danger svg { color: var(--danger); }

/* ── Google sign-in ─────────────────────────────────────────── */
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: .86rem;
  font-weight: 600;
  color: var(--text);
  transition: var(--ease);
}
.btn-google:hover { background: var(--bg-inset); }
.btn-google svg { width: 17px; height: 17px; }
@media (max-width: 620px) { .btn-google span { display: none; } .btn-google { padding-inline: 10px; } }

/* ── Ad slot ────────────────────────────────────────────────── */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  max-width: 728px;
  margin: 0 auto;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  overflow: hidden;
  position: relative;
}
.ad-slot::before {
  content: 'Advertisement';
  position: absolute;
  top: 5px; right: 10px;
  font-size: .62rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* แบนเนอร์ 728x90 เฉพาะจอกว้าง
   ตัวสคริปต์ถูกแทรกโดย ads.js ซึ่งจะแสดงช่องนี้ให้เองเมื่อจอกว้างพอ
   overflow กับ max-width กันไม่ให้กรอบ 728px ดันหน้าให้เลื่อนแนวนอนในทุกกรณี */
.ad-leaderboard {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 756px;
  min-height: 90px;
  margin: 28px auto;
  padding: 0;
  overflow: hidden;
  position: relative;
}
.ad-leaderboard::before {
  content: 'Advertisement';
  position: absolute;
  top: -14px; right: 2px;
  font-size: .62rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.ad-leaderboard iframe { display: block; border: 0; max-width: 100%; }

@media (max-width: 767px) {
  /* มือถือใช้ช่อง 320x50 ซึ่ง ads.js เป็นคนเลือกให้เอง
     ตั้ง max-width ไว้เท่าความกว้างของช่อง เพื่อให้ป้าย Advertisement
     เกาะขอบขวาของแบนเนอร์จริง ไม่ใช่ลอยไปสุดขอบจอ */
  .ad-leaderboard { max-width: 320px; min-height: 50px; margin: 20px auto; }
}

/* ── Footer ─────────────────────────────────────────────────── */
.footer { background: var(--bg); border-top: 1px solid var(--border); padding: 40px 0 26px; }
/* คอลัมน์ลิงก์เรียงแถวเดียว
   หมายเหตุ ห้ามใช้ repeat(auto-fit, ...) ร่วมกับหน่วย fr ในบรรทัดเดียวกัน
   เพราะผิดกฎ CSS Grid เบราว์เซอร์จะทิ้งทั้งบรรทัดแล้วเหลือคอลัมน์เดียว */
.footer-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 24px;
  margin-bottom: 28px;
}
/* บล็อกแบรนด์กินเต็มความกว้างด้านบน คอลัมน์ลิงก์จึงได้พื้นที่เท่ากันทั้งแถว */
.footer-brand {
  grid-column: 1 / -1;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.footer-about { color: var(--text-muted); font-size: .86rem; line-height: 1.7; margin-top: 10px; max-width: 300px; }
.footer-heading { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); margin-bottom: 12px; }
.footer-link {
  display: block;
  padding: 7px 0;
  font-size: .87rem;
  color: var(--text-muted);
  text-decoration: none;
}
.footer-link:hover { color: var(--accent); text-decoration: none; }
.footer-bottom {
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: .82rem;
  color: var(--text-faint);
  text-align: center;
}

/* ── Prose (บทความ / นโยบาย) ────────────────────────────────── */
.prose { color: var(--text-muted); font-size: .94rem; line-height: 1.85; }
.prose h2 { color: var(--text); margin: 28px 0 10px; font-size: 1.2rem; }
.prose h3 { color: var(--text); margin: 20px 0 8px; font-size: 1rem; }
.prose h2:first-child, .prose h3:first-child { margin-top: 0; }
.prose p { margin-bottom: 12px; }
.prose ul, .prose ol { padding-left: 22px; margin-bottom: 14px; }
.prose li { margin-bottom: 6px; }
.prose strong { color: var(--text); font-weight: 600; }
.prose code {
  font-family: var(--mono);
  font-size: .87em;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--bg-inset);
  color: var(--text);
}

/* ── Breadcrumb ─────────────────────────────────────────────── */
.breadcrumb { font-size: .8rem; color: var(--text-faint); margin-bottom: 14px; }
.breadcrumb a {
  display: inline-block;
  padding: 6px 0;
  color: var(--text-muted);
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb span + span::before { content: '/'; margin: 0 7px; color: var(--text-faint); }

/* ================================================================
   QR Studio — เครื่องมือสร้าง QR บนหน้าแรก
   ================================================================ */
.studio { padding: 28px 0 8px; }
.studio-head { margin-bottom: 18px; }
.studio-head h1 { margin-bottom: 6px; }
.studio-head p { color: var(--text-muted); font-size: .93rem; }

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 20px;
  align-items: start;
}
/* กันคอลัมน์ถูกดันกว้างเกินจอ เพราะค่า min ของ track เป็น min-content ของลูก */
.studio-grid > * { min-width: 0; }

/* แถบเลือกประเภท เลื่อนแนวนอนบนมือถือ กริดบนจอใหญ่ */
.typebar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 68px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transition: var(--ease);
}
.type-btn svg { width: 20px; height: 20px; }
.type-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-inset); }
.type-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-subtle);
}

@media (max-width: 700px) {
  .typebar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    padding-bottom: 6px;
    margin-inline: -4px;
    padding-inline: 4px;
    scrollbar-width: none;
  }
  .typebar::-webkit-scrollbar { display: none; }
  .type-btn { flex: 0 0 auto; width: 92px; scroll-snap-align: start; }
}

/* ── แถบทางลัดไปเครื่องมืออื่น ──────────────────────────────
   ใช้กลไกเลื่อนแนวนอนชุดเดียวกับ .typebar ด้านบน
   เพื่อให้บนมือถือเป็นแถวเดียวที่ปัดได้ ไม่ตกบรรทัดจนหน้าสูงขึ้น */
.quicktools { margin: 0 0 20px; }
.quicktools-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}
.quicktools-head h2 { font-size: .95rem; font-weight: 700; }
.quicktools-head a { margin-left: auto; font-size: .85rem; font-weight: 600; white-space: nowrap; }

.quicktools-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 6px;
  margin-inline: -4px;
  padding-inline: 4px;
  scrollbar-width: none;
}
.quicktools-row::-webkit-scrollbar { display: none; }

.quicktool {
  flex: 0 0 auto;
  scroll-snap-align: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text);
  font-size: .87rem;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  transition: var(--ease);
}
.quicktool:hover {
  border-color: var(--accent-border);
  background: var(--accent-subtle);
  color: var(--accent);
  text-decoration: none;
}
.quicktool svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--accent); }
.quicktool:hover svg { color: inherit; }

/* ปุ่มเครื่องมือในเมนูบน ให้เด่นกว่าลิงก์เมนูอื่น */
.nav-cta {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}
.nav-cta:hover { background: var(--accent-subtle); color: var(--accent-hover); }

/* กล่องพรีวิว */
.preview-card { position: sticky; top: calc(var(--header-h) + 16px); }
.qr-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  padding: 22px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.qr-stage canvas, .qr-stage svg, .qr-stage img { width: 100%; height: auto; }
.qr-stage .skeleton { width: 100%; aspect-ratio: 1; }

.qr-caption {
  margin-top: 12px;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
  word-break: break-all;
}
.qr-caption-empty { font-family: var(--font); color: var(--text-faint); }

.dl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.dl-grid .btn-block { grid-column: 1 / -1; }

/* แถบจุดขาย */
.usp {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.usp-item { display: flex; gap: 11px; align-items: flex-start; }
.usp-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  color: var(--accent);
}
.usp-icon svg { width: 17px; height: 17px; }
.usp-title { font-size: .89rem; font-weight: 600; margin-bottom: 2px; }
.usp-text { font-size: .82rem; color: var(--text-muted); line-height: 1.55; }

/* การ์ดฟีเจอร์ */
.feature { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.feature-icon {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  color: var(--accent);
}
.feature-icon svg { width: 18px; height: 18px; }
.feature h3 { font-size: .95rem; margin-bottom: 6px; }
.feature p { font-size: .85rem; color: var(--text-muted); line-height: 1.65; }

/* ขั้นตอน 3 ข้อ */
.steps { counter-reset: step; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; }
.step { position: relative; padding-left: 44px; }
.step::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0; top: 0;
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: .85rem;
  font-weight: 700;
}
.step h3 { font-size: .95rem; margin-bottom: 5px; }
.step p { font-size: .85rem; color: var(--text-muted); line-height: 1.65; }

/* ── ไอคอนเครื่องมือ ─────────────────────────────────────────
   แต่ละหมวดมีสีของตัวเอง ทำให้กวาดสายตาหาเครื่องมือในกริดได้เร็วขึ้น
   ใช้ตัวแปร --cat-fg กับ --cat-bg ที่ตั้งไว้บนการ์ด ไอคอนจึงรับสีตามหมวดเอง */
.tool-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--cat-bg, var(--accent-subtle));
  color: var(--cat-fg, var(--accent));
  flex-shrink: 0;
  transition: transform var(--ease);
}
.tool-icon svg { width: 22px; height: 22px; }

a:hover > .tool-icon { transform: scale(1.08) rotate(-3deg); }

[data-cat="qr"]    { --cat-fg: #4f46e5; --cat-bg: #eef2ff; }
[data-cat="pdf"]   { --cat-fg: #b42318; --cat-bg: #fef3f2; }
[data-cat="image"] { --cat-fg: #6d28d9; --cat-bg: #f5f3ff; }
[data-cat="dev"]   { --cat-fg: #0e7490; --cat-bg: #ecfeff; }
[data-cat="calc"]  { --cat-fg: #b54708; --cat-bg: #fffaeb; }

[data-theme="dark"] [data-cat="qr"]    { --cat-fg: #a5a0ff; --cat-bg: #221f42; }
[data-theme="dark"] [data-cat="pdf"]   { --cat-fg: #ff9d94; --cat-bg: #2e1a17; }
[data-theme="dark"] [data-cat="image"] { --cat-fg: #c9b6fd; --cat-bg: #261f45; }
[data-theme="dark"] [data-cat="dev"]   { --cat-fg: #7fdbe8; --cat-bg: #102c33; }
[data-theme="dark"] [data-cat="calc"]  { --cat-fg: #fbd27a; --cat-bg: #2d2412; }

/* บทความ */
.article-card {
  display: block;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  text-decoration: none;
  color: inherit;
  transition: var(--ease);
}
.article-card:hover { border-color: var(--border-strong); background: var(--bg-subtle); text-decoration: none; }
.article-card h3 { font-size: .95rem; margin-bottom: 6px; }
.article-card p { font-size: .85rem; color: var(--text-muted); line-height: 1.65; }

/* การ์ดเครื่องมือบนหน้าแรก มีไอคอนนำหน้าชื่อ */
.tool-tile { display: flex; flex-direction: column; gap: 10px; }
.tool-tile h3 { margin-bottom: 4px; }
.tool-tile:hover { border-color: var(--cat-fg); background: var(--cat-bg); }

/* CTA ปิดท้าย */
.cta {
  text-align: center;
  padding: 40px 24px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-lg);
  background: var(--accent-subtle);
}
.cta h2 { margin-bottom: 8px; }
.cta p { color: var(--text-muted); margin-bottom: 20px; font-size: .93rem; }

@media (max-width: 900px) {
  .studio-grid { grid-template-columns: minmax(0, 1fr); }
  .preview-card { position: static; }
  .qr-stage { max-width: 340px; margin-inline: auto; }
}

@media (max-width: 560px) {
  :root { --header-h: 56px; }
  .container { padding-inline: 16px; }
  .section { padding: 40px 0; }
  .card { padding: 16px; }
  .dl-grid { grid-template-columns: 1fr; }
}

/* ── Footer ตามขนาดจอ ────────────────────────────────────────
   ลดจำนวนคอลัมน์เป็นขั้น ๆ แทนที่จะยุบเหลือคอลัมน์เดียวทันที
   จะได้ไม่กลายเป็นรายการลิงก์ยาวเหยียดบนมือถือ */
@media (max-width: 1000px) {
  .footer-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
  .footer-about { max-width: none; }
}

/* ── พื้นที่กดบนจอสัมผัส ──────────────────────────────────────
   นิ้วต้องการเป้าอย่างน้อย 44px ทุกอย่างที่กดได้จึงถูกยกให้ถึงขนาดนั้น
   ใช้ pointer: coarse เพื่อไม่ให้เมาส์บนเดสก์ท็อปได้ปุ่มใหญ่เกินจำเป็น */
@media (pointer: coarse), (max-width: 700px) {
  .icon-btn,
  .burger,
  .btn-google,
  .menu-trigger,
  .btn-sm,
  .seg-item,
  .chip { min-height: 44px; }

  .icon-btn, .burger { width: 44px; }
  .swatch { width: 46px; height: 46px; }

  .color-field { min-height: 54px; padding: 5px 12px 5px 5px; }
  .color-field input[type="color"] { width: 44px; height: 44px; }

  .footer-link { padding: 11px 0; }

  .brand { min-height: 44px; }

  .menu-item { min-height: 44px; }
  .accordion summary { min-height: 56px; }
  .disclosure > summary { min-height: 52px; }
}
