/* =====================================================================
   หน้าทดลองพิมพ์ (preview.html) — รีดีไซน์ 12 พ.ย. 2569
   คอม: ฟอนต์ (ซ้าย) · เวที + ข้อความ (กลาง) · ปรับแต่ง (ขวา) — ทุกอย่างอยู่ในจอเดียว
   มือถือ: เวทีขึ้นก่อน · แถบแท็บติดจอ · ฟอนต์ · ปรับแต่งแบบพับเก็บ
   ===================================================================== */

/* ── โครง 3 คอลัมน์ ── */
.tool-layout {
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  grid-template-areas: "fonts main controls";
  background: var(--bg);
}
.tool-sidebar { background: var(--bg-card); }
.tool-sidebar:not(.tool-controls) { grid-area: fonts; }
.tool-main { grid-area: main; padding: 28px; gap: 18px; }
.tool-controls { grid-area: controls; border-right: 0; border-left: 1px solid var(--border); }

/* ── หัวข้อหมวดในแถบข้าง ── */
.sidebar-section { padding: 20px 22px; }
.sidebar-label {
  font-size: var(--fs-small) !important;
  font-weight: 700 !important;
  color: var(--text-dark) !important;
  letter-spacing: 0 !important;
  text-transform: none !important;
  margin-bottom: 12px !important;
}

/* ── ค้นหา + รายชื่อฟอนต์ ── */
.font-search-input {
  border-radius: var(--radius-ctl) !important;
  min-height: 44px;
  font-size: var(--fs-ui) !important;
}
.font-search-input:focus { border-color: var(--plum) !important; box-shadow: 0 0 0 3px rgba(150, 72, 110, 0.12) !important; }
.font-item { border-radius: var(--radius-ctl) !important; }
.font-item.active { background: var(--pink-light) !important; border-color: var(--plum) !important; box-shadow: inset 0 0 0 1px var(--plum); }

/* ── การ์ดพิมพ์ข้อความ + เวที: เชื่อมเป็นชุดเดียวกัน ── */
.text-input-card,
.preview-canvas-card {
  border-radius: var(--radius-lg) !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 6px 22px rgba(74, 58, 46, 0.06) !important;
  background: var(--bg-card) !important;
}
.text-input-card textarea {
  font-size: var(--fs-lead) !important;
  min-height: 72px;
}
.text-input-card textarea:focus { outline: none; }
.text-input-card:focus-within { border-color: var(--plum) !important; box-shadow: 0 0 0 3px rgba(150, 72, 110, 0.1), 0 6px 22px rgba(74, 58, 46, 0.06) !important; }

/* แท็บมุมมอง */
.view-tabs { border-radius: var(--radius-ctl) !important; background: var(--bg-soft) !important; padding: 3px !important; border: 1px solid var(--border); }
.view-tab { border-radius: 8px !important; min-height: 36px; }
.view-tab.active { background: var(--bg-card) !important; color: var(--text-dark) !important; box-shadow: 0 1px 3px rgba(74, 58, 46, 0.14) !important; }

/* แถบหัวเวที */
.canvas-toolbar { padding: 12px 16px !important; background: var(--bg) !important; }
.canvas-info strong { font-family: var(--font-heading); font-size: var(--fs-lead); color: var(--text-dark); }
.canvas-actions .btn { border-radius: var(--radius-ctl) !important; }
.preview-canvas { min-height: 380px; }

/* ── ตัวปรับแต่ง ── */
.range-row input[type="range"] { accent-color: var(--plum); }
.range-val {
  min-width: 52px; text-align: center;
  padding: 3px 8px; border-radius: var(--radius-xs);
  background: var(--bg-soft); color: var(--text-dark) !important; font-weight: 600;
}
.weight-grid { gap: 6px !important; }
.weight-btn { border-radius: var(--radius-ctl) !important; min-height: 38px; }
.weight-btn.active { background: var(--pink-light) !important; border-color: var(--plum) !important; color: var(--plum) !important; }
.swatch, .bg-swatch { border-radius: 50% !important; }
.swatch.active, .bg-swatch.active { box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px var(--plum) !important; }
.color-picker, .hex-input { border-radius: var(--radius-ctl) !important; }
.toggle.on, .toggle.active, .toggle[aria-pressed="true"] { background: var(--plum) !important; }
.align-btn { border-radius: var(--radius-ctl) !important; }
.align-btn.active { background: var(--pink-light) !important; border-color: var(--plum) !important; color: var(--plum) !important; }
.preset-btn { border-radius: var(--radius-ctl) !important; min-height: 38px; }
.preset-btn:hover { border-color: var(--plum) !important; color: var(--plum) !important; }

/* ── กล่องชวนซื้อ: การ์ดพาสเทลแทนแถบน้ำตาลเข้ม ── */
.export-panel {
  border-radius: var(--radius-lg) !important;
  background:
    radial-gradient(120% 160% at 0% 0%, rgba(248, 192, 217, 0.55) 0%, rgba(248, 192, 217, 0) 55%),
    radial-gradient(100% 160% at 100% 100%, rgba(195, 174, 222, 0.5) 0%, rgba(195, 174, 222, 0) 60%),
    var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-dark) !important;
  box-shadow: none !important;
}
.export-info { color: var(--text-mid) !important; }
.export-info strong { font-family: var(--font-heading); font-size: var(--fs-h4); color: var(--text-dark) !important; }
.export-btns .btn { border-radius: var(--radius-ctl) !important; min-height: 46px; }
.export-btns .btn-white { background: var(--bg-card) !important; border: 1px solid var(--border) !important; color: var(--text-dark) !important; }

/* ── จอกลาง (แท็บเล็ต/โน้ตบุ๊กเล็ก): แผงปรับแต่งย้ายไปใต้เวที ── */
@media (max-width: 1200px) and (min-width: 769px) {
  .tool-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    grid-template-areas: "fonts main" "fonts controls";
  }
  .tool-controls {
    position: static !important; height: auto !important; overflow: visible !important;
    border-left: 0; border-top: 1px solid var(--border);
    display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0 28px 28px; border: 1px solid var(--border); border-radius: var(--radius-lg);
  }
  .tool-controls .sidebar-section { border-bottom: 1px solid var(--border); }
  .tool-controls .sidebar-section:nth-child(odd) { border-right: 1px solid var(--border); }
}

/* ── มือถือ ── */
@media (max-width: 768px) {
  .tool-layout { grid-template-areas: none; display: flex !important; flex-direction: column; }
  .tool-main { order: 1; }
  .tool-sidebar:not(.tool-controls) { order: 2; }
  .tool-controls { order: 3; border-left: 0; }

  .mobile-tool-nav {
    display: flex !important;
    gap: 6px !important;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 10px 14px !important;
    background: var(--bg) !important;
    backdrop-filter: none !important;
    border-bottom: 1px solid var(--border);
  }
  .mobile-tool-nav::-webkit-scrollbar { display: none; }
  .mobile-tool-btn {
    flex: 0 0 auto;
    min-height: 40px !important;
    padding: 0 16px !important;
    border-radius: var(--radius-ctl) !important;
    font-size: var(--fs-small) !important;
    font-weight: 600 !important;
    background: var(--bg-card) !important;
  }
  .mobile-tool-btn.active { background: var(--btn) !important; border-color: var(--btn) !important; color: #fff !important; }

  .sidebar-section { border-radius: var(--radius-lg) !important; }
  .sidebar-label {
    justify-content: space-between !important;
    text-align: left !important;
    min-height: 52px;
    margin-bottom: 0 !important;
    font-size: var(--fs-ui) !important;
  }
  .sidebar-section:not(.collapsed) .sidebar-label { margin-bottom: 12px !important; }
  .sidebar-label::after {
    width: 28px; height: 28px; border-radius: 50%;
    display: grid !important; place-items: center;
    background: var(--bg-soft); color: var(--text-mid); font-size: var(--fs-body);
  }
  .tool-controls { padding-top: 0 !important; }
  .tool-controls .sidebar-section + .sidebar-section { margin-top: 10px; }
  .preview-canvas { min-height: clamp(220px, 40vh, 320px); }
  .text-input-card textarea { font-size: 16px !important; } /* กัน iOS ซูม */
  .export-btns { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }

  /* รายชื่อฟอนต์ 140+ ตัว: เลื่อนในกล่อง ไม่ดันส่วนปรับแต่งลงไปไกล */
  #fontList { max-height: 360px; overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; }
  /* แถบหัวเวที: ข้อมูลอยู่บรรทัดเดียว ปุ่มสองปุ่มเคียงกัน */
  .canvas-toolbar { flex-direction: column; align-items: stretch !important; gap: 10px !important; }
  .canvas-info { flex-direction: row !important; flex-wrap: wrap; align-items: center !important; gap: 4px 12px !important; }
  .canvas-info > span { display: inline-flex !important; justify-content: flex-start !important; align-items: center; gap: 6px; width: auto !important; flex: 0 0 auto !important; }
  .canvas-info > span:first-child { width: 100% !important; flex-basis: 100% !important; }
  .canvas-info > span span { width: auto !important; }
  /* หมวดปรับแต่งที่พับเก็บ: เตี้ยลง กดง่าย */
  .sidebar-section { padding: 4px 16px !important; }
  .sidebar-section:not(.collapsed) { padding-bottom: 16px !important; }
  .canvas-actions { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px !important; }
  .canvas-actions .btn { width: 100% !important; justify-content: center; min-height: 42px; }
  .text-input-card textarea { min-height: 64px; }
}
@media (max-width: 768px) {
  /* หัวกล่องพิมพ์: ป้าย + ล้าง/คัดลอก อยู่บรรทัดเดียว */
  .text-input-header { flex-direction: row !important; flex-wrap: nowrap !important; align-items: center !important; justify-content: space-between !important; gap: 8px !important; }
  .text-input-actions { flex-shrink: 0; }
}
@media (max-width: 768px) {
  .text-input-label { white-space: nowrap; flex: 1 1 auto; min-width: 0; }
  .text-input-actions { width: auto !important; display: flex !important; gap: 4px !important; }
  .text-input-actions .btn { width: auto !important; min-height: 36px; padding: 0 10px !important; }
}
