:root {
  --bg: #f4f6f9;
  --ink: #1e1e2e;
  --muted: #6b7280;
  --line: #e2e8f0;
  --pink: #e85d75;
  --pink-deep: #c23a55;
  --pink-light: #fff0f3;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --green-border: #86efac;
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --blue-border: #93c5fd;
  --amber: #d97706;
  --amber-light: #fffbeb;
  --red: #dc2626;
  --red-light: #fef2f2;
  --red-border: #fca5a5;
  --shadow: 0 4px 12px rgba(0,0,0,.08);
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* overflow-x: hidden — .history-sidebar ซ่อนตัวด้วย translateX(100%) แต่ยังกินความกว้างจริง
   บนมือถือ 440px เลยเลื่อนแนวนอนได้ 260px ทั้งที่ไม่มีอะไรให้ดู (เจอด้วยเกณฑ์ S6 · 2026-07-31) */
html { overflow-x: hidden; }
body { background: var(--bg); color: var(--ink); font-family: "Noto Sans Thai","Segoe UI",sans-serif; font-size: 13px; line-height: 1.6; overflow-x: hidden; }

/* Header */
.header { background: #fff; border-bottom: 1px solid var(--line); padding: 0 20px; display: flex; align-items: center; justify-content: space-between; height: 52px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.logo { font-size: 15px; font-weight: 800; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.logo span { font-weight: 400; font-size: 12px; color: var(--muted); }
.header-actions { display: flex; gap: 8px; align-items: center; }
.btn-guide { font-size: 12px; font-weight: 600; color: var(--pink); background: var(--pink-light); border: 1px solid #fecdd3; border-radius: 20px; padding: 5px 14px; cursor: pointer; text-decoration: none; }
.btn-history { font-size: 12px; font-weight: 600; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 5px 14px; cursor: pointer; display: flex; align-items: center; gap: 5px; }
.history-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pink); }

/* Tabs */
.tabs { background: #fff; border-bottom: 1px solid var(--line); padding: 0 20px; display: flex; gap: 2px; }
.tab { padding: 12px 16px; font-size: 13px; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; color: var(--muted); white-space: nowrap; transition: color .15s; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--pink); border-bottom-color: var(--pink); }

/* Tab content */
.tab-content { display: none; padding: 20px; }
.tab-content.active { display: block; }

/* Three panel */
.three-panel { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
@media (max-width: 900px) { .three-panel { grid-template-columns: 1fr; } }
.panel { padding: 16px; }
.panel-input { background: #fff; border-right: 1px solid var(--line); }
.panel-result { background: #fafafa; border-right: 1px solid var(--line); }
.panel-fix { background: var(--green-light); }
.panel-rec { background: var(--blue-light); }
.panel-header { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding-bottom: 10px; margin-bottom: 12px; border-bottom: 2px solid var(--line); color: var(--muted); }
.panel-header.green { color: var(--green); border-bottom-color: var(--green-border); }
.panel-header.blue { color: var(--blue); border-bottom-color: var(--blue-border); }

/* Form elements */
textarea, input[type=text] { width: 100%; border: 1.5px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; font-family: inherit; color: var(--ink); background: #fafafa; transition: border .15s; }
textarea { height: 120px; resize: vertical; min-height: 80px; }
textarea:focus, input[type=text]:focus { outline: none; border-color: var(--pink); background: #fff; }
textarea::placeholder, input[type=text]::placeholder { color: #c0c4cc; }

/* ไฮไลต์คำที่ผิดกฎในกล่องคำเคลม (highlight.js)
   ชั้นไฮไลต์ซ้อนอยู่ "หลัง" textarea — ตอนมีคำผิดจะให้ตัวหนังสือที่มองเห็นมาจากชั้นนี้
   ส่วน textarea ทำตัวอักษรโปร่งใสแต่ยังพิมพ์/เลื่อน/เลือกได้เหมือนเดิม
   ค่า padding/ขนาดตัวอักษร/line-height ต้องตรงกับ textarea เป๊ะ ไม่งั้นไฮไลต์เลื่อนหลุดคำ */
.hl-wrap { position: relative; }
.hl-wrap textarea { display: block; position: relative; z-index: 1; }
.hl-backdrop {
  position: absolute; inset: 0; z-index: 0;
  border: 1.5px solid transparent; border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit; font-size: 13px; line-height: normal;
  white-space: pre-wrap; overflow-wrap: break-word;
  overflow: hidden; color: transparent; pointer-events: none;
}
.hl-wrap.hl-on .hl-backdrop { color: var(--ink); background: #fafafa; }
.hl-wrap.hl-on:focus-within .hl-backdrop { background: #fff; }
.hl-wrap.hl-on textarea { color: transparent; background: transparent; caret-color: var(--ink); }
.hl-wrap.hl-on textarea::selection { background: rgba(37,99,235,.28); }
mark.hl-fixed {
  background: #dcfce7; color: #15803d; border-radius: 3px;
  box-shadow: 0 0 0 1px var(--green-border); padding: 0 1px;
}
mark.hl-bad {
  background: #ffe0e4; color: var(--red); border-radius: 3px;
  box-shadow: 0 0 0 1px var(--red-border); padding: 0 1px;
}
.hl-note { font-size: 11px; font-weight: 600; color: var(--red); margin-top: 7px; line-height: 1.5; }
.hl-note.fixed-note { color: var(--green); }

.chips-label { font-size: 11px; font-weight: 600; color: var(--muted); margin: 10px 0 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 6px; cursor: pointer; border: 1.5px solid #fecdd3; background: #ffe4e8; color: #be123c; transition: all .15s; user-select: none; }
.chip.off { background: #f1f5f9; color: var(--muted); border-color: var(--line); }
.btn-check { width: 100%; margin-top: 12px; background: var(--pink); color: #fff; border: none; border-radius: 8px; padding: 10px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit; transition: background .15s; }
.btn-check:hover { background: var(--pink-deep); }
.btn-check:disabled { background: #ccc; cursor: not-allowed; }

/* Result cards */
.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-card { border-radius: 8px; padding: 10px 12px; border: 1.5px solid transparent; font-size: 12px; }
.result-card.fail { background: var(--red-light); border-color: var(--red-border); }
.result-card.pass { background: var(--green-light); border-color: var(--green-border); }
.result-card.warn { background: var(--amber-light); border-color: #fcd34d; }
.result-platform { font-weight: 700; margin-bottom: 3px; }
.result-platform.fail { color: var(--red); }
.result-platform.pass { color: var(--green); }
.result-platform.warn { color: var(--amber); }
.result-reason { color: #6b7280; font-size: 11px; line-height: 1.5; }

/* Fixed claim */
.fixed-box { white-space: pre-wrap; overflow-wrap: break-word; background: #fff; border: 1.5px solid var(--green-border); border-radius: 8px; padding: 12px; font-size: 13px; color: #15803d; min-height: 120px; line-height: 1.7; overflow: auto; resize: vertical; }
.pass-label { font-size: 11px; color: var(--green); font-weight: 700; margin-top: 6px; }
.action-row { display: flex; gap: 6px; margin-top: 10px; }
.btn-copy { flex: 1; background: var(--green); color: #fff; border: none; border-radius: 7px; padding: 8px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit; }
.btn-edit { flex: 1; background: #fff; color: var(--green); border: 1.5px solid var(--green-border); border-radius: 7px; padding: 8px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit; }
.btn-save-lib { width: 100%; margin-top: 6px; background: #fff; color: var(--green); border: 1.5px solid var(--green); border-radius: 7px; padding: 7px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit; }

/* Rec items */
.rec-list { display: flex; flex-direction: column; gap: 8px; }
.rec-card { background: #fff; border: 1.5px solid var(--blue-border); border-radius: 8px; padding: 10px 12px; font-size: 12px; }
.rec-title { color: var(--blue); font-weight: 700; margin-bottom: 3px; }
.rec-body { color: #6b7280; font-size: 11px; line-height: 1.5; }

/* Upload zone */
.upload-zone { border: 2px dashed #d1d5db; border-radius: 10px; padding: 20px; text-align: center; background: #f9fafb; cursor: pointer; transition: all .15s; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--pink); background: var(--pink-light); }
.upload-zone input { display: none; }
.uz-icon { font-size: 28px; margin-bottom: 6px; }
.uz-label { font-weight: 700; font-size: 13px; color: #374151; }
.uz-hint { font-size: 11px; color: #9ca3af; margin-top: 3px; }
.upload-preview { margin-top: 8px; }
.upload-preview img { max-width: 100%; max-height: 120px; border-radius: 8px; border: 1px solid var(--line); }
.divider { text-align: center; font-size: 11px; color: #9ca3af; margin: 8px 0; }
.tr-note { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 10px; }
.tr-dir { display: flex; gap: 6px; margin-bottom: 14px; }
.tr-dir-btn { font-size: 12px; font-weight: 700; padding: 7px 16px; border-radius: 20px; cursor: pointer; border: 1.5px solid var(--line); background: #fff; color: var(--muted); font-family: inherit; transition: all .15s; }
.tr-dir-btn.active { background: var(--pink); color: #fff; border-color: var(--pink); }

/* Batch */
.batch-grid { display: grid; grid-template-columns: 280px 1fr; gap: 0; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); }
@media (max-width: 900px) { .batch-grid { grid-template-columns: 1fr; } }
.batch-input { background: #fff; border-right: 1px solid var(--line); padding: 16px; }
.batch-result { background: #fafafa; padding: 16px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { background: #f1f5f9; color: #374151; font-weight: 700; padding: 8px 10px; text-align: left; border-bottom: 2px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.t-fail { color: var(--red); font-weight: 700; }
.t-pass { color: var(--green); font-weight: 700; }
.t-warn { color: var(--amber); font-weight: 700; }

/* Library */
.lib-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.lib-filter { padding: 5px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; border: 1.5px solid var(--line); background: #fff; color: var(--muted); transition: all .15s; }
.lib-filter.active { background: var(--pink); color: #fff; border-color: var(--pink); }
.lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 900px) { .lib-grid { grid-template-columns: 1fr 1fr; } }
.lib-card { position: relative; background: #fff; border: 1.5px solid var(--line); border-radius: 10px; padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.lib-del { position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; line-height: 1; border: none; border-radius: 50%; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; font-family: inherit; }
.lib-del:hover { background: #fee2e2; color: #b91c1c; }
.lib-text { font-size: 13px; color: var(--ink); line-height: 1.6; margin-bottom: 8px; }
.lib-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tag-pass { font-size: 10px; background: var(--green-light); color: var(--green); padding: 2px 7px; border-radius: 4px; font-weight: 700; }
.tag-cat { font-size: 10px; background: #f1f5f9; color: var(--muted); padding: 2px 7px; border-radius: 4px; }
.btn-lib-copy { width: 100%; background: var(--green); color: #fff; border: none; border-radius: 6px; padding: 6px; font-size: 11px; font-weight: 700; cursor: pointer; font-family: inherit; }
.lib-empty { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }

/* History Sidebar */
.history-sidebar { position: fixed; right: 0; top: 52px; bottom: 0; width: 280px; background: #fff; border-left: 1px solid var(--line); box-shadow: -4px 0 16px rgba(0,0,0,.06); padding: 16px; overflow-y: auto; transform: translateX(100%); transition: transform .25s; z-index: 100; }
.history-sidebar.open { transform: translateX(0); }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sidebar-title { font-size: 13px; font-weight: 700; }
.sidebar-close { font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; background: none; border: none; }
.hist-item { background: #f9fafb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: background .1s; }
.hist-item:hover { background: #f1f5f9; }
.hist-type { font-size: 10px; color: var(--muted); margin-bottom: 3px; }
.hist-claim { font-size: 12px; font-weight: 600; color: var(--ink); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.hist-meta { display: flex; align-items: center; justify-content: space-between; }
.hist-time { font-size: 10px; color: var(--muted); }
.badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 4px; }
.badge.fail { background: var(--red-light); color: var(--red); }
.badge.pass { background: var(--green-light); color: var(--green); }
.hist-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 20px 0; }
.hist-thumb { width: 100%; max-height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); margin: 6px 0; display: block; background: var(--bg); }

/* Loading spinner */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; margin-right: 6px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* แถบอ้างอิงแหล่งข้อมูล (ท้ายหน้า เห็นได้ทุกแท็บ) */
.refs { border-top: 1px solid var(--line); background: #fff; padding: 14px 20px 18px; margin-top: 8px; }
.refs-head { font-size: 12px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.refs-list { display: flex; flex-wrap: wrap; gap: 6px; }
.ref { font-size: 11.5px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; text-decoration: none; transition: color .15s, border-color .15s, background .15s; }
.ref:hover { color: var(--pink); border-color: #fecdd3; background: var(--pink-light); }
.ref span { opacity: .75; }
.refs-note { font-size: 10.5px; color: var(--muted); margin-top: 9px; line-height: 1.5; }

/* Toast notification */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px); background: #1e1e2e; color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 13px; font-weight: 600; z-index: 999; transition: transform .3s; pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); }
