:root {
  color-scheme: light;
  --bg: #f1f5f9;        /* พื้นหลังหน้า (slate-100) */
  --bg2: #f8fafc;       /* พื้นผิวอ่อน: input/ปุ่ม/หัวตาราง/ชิป (slate-50) */
  --card: #ffffff;      /* การ์ด/พาเนล */
  --border: #e2e8f0;    /* เส้นขอบ (slate-200) */
  --text: #1e293b;      /* ตัวอักษรหลัก (slate-800) */
  --muted: #64748b;     /* ตัวอักษรรอง (slate-500) */
  --primary: #2563eb;   /* แบรนด์ น้ำเงิน (brand-600) */
  --primary-d: #1d4ed8; /* น้ำเงินเข้ม (brand-700) */
  --ok: #16a34a;        /* เขียว (green-600) */
  --warn: #d97706;      /* ส้ม (amber-600) */
  --danger: #e11d48;    /* แดงชมพู (rose-600) */
  --radius: 16px;
  --shadow-soft: 0 1px 2px rgba(37,99,235,.06), 0 10px 30px -12px rgba(37,99,235,.22);
  --font-mono: 'Share Tech Mono', ui-monospace, "Cascadia Code", Consolas, monospace;
}

html { font-size: 16px; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* Inter = อังกฤษ (เข้ากับธีม minimal), Noto Sans Thai = ไทย (fallback ต่อ glyph อัตโนมัติ) */
  font-family: 'Inter', 'Noto Sans Thai', ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 16px; }
.err { color: var(--danger); font-size: 16px; margin-top: 8px; min-height: 18px; }
.msg { color: var(--ok); font-size: 16px; }

/* ── Login ── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; width: min(360px, 90vw);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: var(--shadow-soft);
}
.login-box h2 { margin: 0; }
.login-box input, .field input, .field textarea {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 13px; font-size: 16.5px; width: 100%;
}
.login-box input:focus, .field input:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
}

/* ── Layout ── */
#appWrap { max-width: 1400px; margin: 0 auto; padding: 16px 28px 48px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px -2px rgba(24,119,242,.45);
}
.logo svg { width: 100%; height: 100%; border-radius: 11px; display: block; }
.server-time { display: inline-flex; align-items: center; white-space: nowrap; }
.top-actions { align-items: center; }

/* ไอคอนนำหน้าหัวข้อ/การ์ด (เส้น lucide) */
.ic { width: 1.15em; height: 1.15em; flex: 0 0 auto; stroke-width: 2; }
.card-label { display: flex; align-items: center; gap: 7px; }
.nav-tab { display: inline-flex; align-items: center; gap: 7px; }
.title {
  font-family: 'Orbitron', 'Inter', sans-serif; font-weight: 800; font-size: 23px;
  letter-spacing: 1.5px; line-height: 1;
  background: linear-gradient(95deg, #2563eb 0%, #1877F2 35%, #e8c468 110%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.sub { color: var(--muted); font-size: 15.5px; }
.top-actions { display: flex; gap: 8px; }

/* ── Buttons ── */
button {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 16px; cursor: pointer;
  transition: .15s; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
button:hover { border-color: var(--primary); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--primary-d); }
button.ghost { background: transparent; }
button.small { padding: 5px 10px; font-size: 15.5px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ── Nav tabs ── */
.nav {
  display: flex; gap: 6px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.nav-tab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 16px; color: var(--muted); font-weight: 600;
  margin-bottom: -1px;
}
.nav-tab:hover { color: var(--text); border-color: transparent; }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); margin-left: 4px; vertical-align: middle;
}

/* ── Cards ── */
.cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px;
}
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-soft);
}
.card-label { color: var(--muted); font-size: 15.5px; margin-bottom: 8px; }
.card-big { font-size: 38.5px; font-weight: 800; line-height: 1; }
.card-big .slash { color: var(--muted); margin: 0 2px; font-weight: 400; }
.card-sub { color: var(--muted); font-size: 14px; margin-top: 8px; }

/* ── สถานะ Token เพจ (monitor) ── */
.token-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.token-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card);
}
.token-row.ok   { border-color: rgba(22,163,74,.35);  background: rgba(22,163,74,.07); }
.token-row.warn { border-color: rgba(217,119,6,.45);  background: rgba(217,119,6,.10); }
.token-row.bad  { border-color: rgba(225,29,72,.45);  background: rgba(225,29,72,.10); }
.token-ic { font-size: 17px; flex-shrink: 0; }
.token-name { font-weight: 700; flex-shrink: 0; }
.token-state { color: var(--muted); font-size: 14.5px; margin-left: auto; text-align: right; }
.token-row.warn .token-state { color: var(--warn); }
.token-row.bad  .token-state { color: var(--danger); }
.token-tail { color: var(--muted); font-size: 13px; font-family: monospace; opacity: .8; }
.token-edit-btn { flex-shrink: 0; }
.token-edit { padding: 10px 14px 4px; }
.token-edit.hidden { display: none; }
.token-input { width: 100%; }
.token-msg.err { color: var(--danger); }
.progress { height: 7px; background: var(--border); border-radius: 99px; margin-top: 12px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--primary); transition: width .4s; border-radius: 99px; }

.badges { display: flex; flex-direction: column; align-items: flex-start; gap: 9px; margin-top: 6px; }
/* บรรทัดสถานะ (มีจุด Live กระพริบ) ในการ์ด "สถานะระบบ" */
/* สถานะระบบ: ตัวอักษรสีปกติ (ดำ/เทา) ให้ "จุด Live เขียวกระพริบ" เป็นตัวบอกสถานะแทน */
.stat-line { display: inline-flex; align-items: center; gap: 8px; font-size: 15.5px; font-weight: 600; color: var(--text); }
.stat-line.on { color: var(--text); }
.stat-line.off { color: var(--danger); }
.badge {
  font-size: 14px; padding: 4px 9px; border-radius: 99px;
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted);
}
.badge.on { color: var(--ok); border-color: var(--ok); }
.badge.off { color: var(--danger); border-color: var(--danger); }

/* ── Panels ── */
.panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-soft);
}
.panel-head {
  font-weight: 700; font-size: 16.5px; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: space-between;
}

.output {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-size: 14px; line-height: 1.5; color: #334155;
  white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
  font-family: inherit; margin: 12px 0 0;
}

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 16px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 14px; text-transform: uppercase; }
td a { color: var(--primary); text-decoration: none; }
td a:hover { text-decoration: underline; }
.del-btn { color: var(--danger); border-color: transparent; padding: 5px 10px; font-size: 15.5px; }
.del-btn:hover { border-color: var(--danger); }

/* ปุ่มไอคอนล้วน (ลบ/แก้ไข) + ลิงก์ไอคอน (ดูโพสต์) ในตาราง */
.icon-btn { padding: 7px; }
.icon-btn .ic { width: 18px; height: 18px; }
.icon-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; color: var(--primary);
  border: 1px solid transparent; transition: .15s;
}
.icon-link:hover { border-color: var(--primary); background: rgba(37,99,235,.08); }
.icon-link .ic { width: 18px; height: 18px; }
.icon-link:hover { text-decoration: none; }

/* หมายเหตุท้ายสถานะระบบ เช่น (เชื่อมต่อแล้ว) */
.stat-note { color: var(--muted); font-weight: 400; font-size: .9em; }
.title-cell { max-width: 360px; word-break: break-all; }
#affTitle { font-family: inherit; font-size: 16.5px; line-height: 1.5; }

/* หัวข้อ panel + ป้ายจำนวน (กัน 'space-between' ดันวงเล็บกระจาย) */
.ph-title { display: inline-flex; align-items: center; gap: 8px; }
.count-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 22px; padding: 0 9px; margin-left: 8px;
  background: var(--primary); color: #fff;
  border-radius: 99px; font-size: 14px; font-weight: 700; line-height: 1;
}

/* ── Toolbar กลาง (ค้นหา + เรียงลำดับ) ใช้ได้ทั้งตารางสินค้า/ข่าว ── */
/* สถิติ engagement */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.stat-tile { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 14px 10px; text-align: center; }
.st-val { font-size: 22px; font-weight: 800; color: var(--primary); }
.st-lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-best { margin-top: 14px; padding: 12px 14px; background: rgba(232,196,104,.12); border: 1px solid rgba(232,196,104,.5); border-radius: 12px; font-size: 15px; }
.stat-best a { margin-left: 6px; color: var(--primary); font-weight: 700; white-space: nowrap; }
@media (max-width: 700px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

/* แท็บแยกประเภทโพสต์ (ทั้งหมด / ข่าว / match-mode) */
.post-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.post-tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--muted);
  border-radius: 999px; font-size: 15px; font-weight: 700; cursor: pointer; transition: .15s;
}
.post-tab:hover { color: var(--text); border-color: var(--primary); }
.post-tab.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.pt-count {
  font-size: 12.5px; font-weight: 800; min-width: 20px; text-align: center;
  padding: 1px 7px; border-radius: 999px; background: rgba(15,23,42,.10); color: inherit;
}
.post-tab.active .pt-count { background: rgba(255,255,255,.25); }

.tbl-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.tbl-search {
  flex: 1; min-width: 200px; display: flex; align-items: center; gap: 9px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 13px;
  transition: .15s;
}
.tbl-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.tbl-search svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.tbl-search input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-size: 16px; font-family: inherit; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 15px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--muted);
  border-radius: 10px; font-size: 15.5px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: .15s;
}
.seg-btn:hover { color: var(--text); border-color: var(--primary); }
.seg-btn.active { color: var(--primary); border-color: var(--primary); background: rgba(37,99,235,.10); }

/* ── Fancy dropdown (สไตล์ + animation เหมือน FixPay) ── */
.fd { position: relative; display: inline-flex; }
.fd-trigger {
  display: inline-flex; align-items: center; gap: 8px; min-width: 120px;
  padding: 9px 13px; border: 1px solid var(--border); background: var(--bg2);
  border-radius: 10px; font-size: 15.5px; font-weight: 600; color: var(--text);
  cursor: pointer; transition: .15s; white-space: nowrap; font-family: inherit;
}
.fd-trigger:hover { border-color: var(--primary); }
.fd-trigger.open { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.fd-label { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; }
.fd-caret { display: inline-flex; color: var(--muted); transition: transform .2s ease; }
.fd-trigger.open .fd-caret { transform: rotate(180deg); }
.fd-caret svg { width: 16px; height: 16px; }
.fd-lead { display: inline-flex; flex: 0 0 auto; }
.fd-lead svg { width: 18px; height: 18px; }

/* ตัวเลือกเพจบนหัว — เด่นแบบเดิม (กรอบน้ำเงิน พื้นฟ้าจาง) */
.fd-trigger.fd-page {
  background: rgba(37,99,235,.10); border: 1.5px solid var(--primary);
  color: var(--primary); font-weight: 700; font-size: 16px;
  border-radius: 12px; padding: 8px 12px; max-width: 520px;
}
.fd-trigger.fd-page .fd-lead, .fd-trigger.fd-page .fd-caret { color: var(--primary); }
.fd-trigger.fd-page:hover { background: rgba(37,99,235,.16); }
.fd-trigger.fd-page.open { box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.fd-panel {
  position: fixed; z-index: 1000; margin: 0; padding: 6px; list-style: none;
  max-height: 320px; overflow: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 1px 2px rgba(37,99,235,.06), 0 10px 30px -12px rgba(37,99,235,.22);
  animation: fdIn .28s ease-out;
}
@keyframes fdIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.fd-panel li { list-style: none; }
.fd-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; border: none; background: none; border-radius: 8px;
  font-size: 15.5px; color: var(--text); cursor: pointer; text-align: left; transition: .12s;
}
.fd-item:hover { background: rgba(37,99,235,.08); }
.fd-item.sel { background: rgba(37,99,235,.12); color: var(--primary); font-weight: 700; }
.fd-item-label { flex: 1; transition: transform .15s ease; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fd-item:hover .fd-item-label { transform: translateX(4px); }
.fd-check { display: inline-flex; color: var(--primary); flex: 0 0 auto; }
.fd-check svg { width: 16px; height: 16px; }

/* ── ปรับแต่งโลโก้ (หน้าตั้งค่า) ── */
.logo-preview {
  display: flex; align-items: center; justify-content: center; min-height: 88px;
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: linear-gradient(95deg, rgba(37,99,235,.05), rgba(232,196,104,.05)); margin-bottom: 14px;
}
.logo-preview .title { font-size: 30px; }
.logo-controls .field { margin-bottom: 14px; }
.logo-controls input[type="range"] { width: 100%; accent-color: var(--primary); }
.logo-colors { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.logo-swatch {
  width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--border);
  cursor: pointer; padding: 0; transition: .15s; position: relative;
}
.logo-swatch:hover { transform: scale(1.12); }
.logo-swatch.sel { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.logo-swatch.grad { background: linear-gradient(95deg, #2563eb 0%, #1877F2 35%, #e8c468 110%); }
.logo-swatch.custom { display: inline-flex; align-items: center; justify-content: center; background: var(--bg2); color: var(--muted); font-size: 18px; font-weight: 700; overflow: hidden; }
.logo-swatch.custom input[type="color"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── ตารางกลาง (การ์ดมีกรอบ ไม่มีเส้นขาด) ── */
.tbl-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tbl { border-collapse: separate; border-spacing: 0; width: 100%; }
.tbl thead th {
  background: var(--bg2); color: var(--muted); font-size: 14px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .3px; padding: 12px 14px;
  box-shadow: inset 0 -1px 0 0 var(--border); text-align: left;
}
/* ใช้ inset box-shadow แทน border-bottom — เส้นคมต่อเนื่อง ไม่หลุดเป็นช่วง ๆ ที่ซูมเศษพิกเซล */
.tbl tbody td { padding: 13px 14px; box-shadow: inset 0 -1px 0 0 var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { box-shadow: none; }
.tbl tbody tr:hover td { background: rgba(15,23,42,.03); }
.tbl td:last-child { white-space: nowrap; }
.tbl td:last-child button + button { margin-left: 6px; }
.aff-date { color: var(--muted); font-size: 15.5px; white-space: nowrap; }
.post-title-en {
  max-width: 760px; line-height: 1.4; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
}
.post-title-th {
  max-width: 760px; margin-top: 4px; line-height: 1.4;
  color: var(--muted); font-size: 15.5px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
}
/* ให้คอลัมน์หัวข้อกินพื้นที่ว่างที่เหลือ (คอลัมน์อื่นแคบ) */
#postsTable th:nth-child(3), #postsTable td:nth-child(3) { width: 100%; }
/* คอลัมน์ "ผลตอบรับ" + "โพสต์" ไม่ตกบรรทัด */
#postsTable th:nth-child(4), #postsTable td:nth-child(4),
#postsTable th:nth-child(5), #postsTable td:nth-child(5) { white-space: nowrap; }

/* ยอดมีส่วนร่วม (ไลก์/คอมเมนต์/แชร์) */
.eng-cell { white-space: nowrap; }
.eng { display: inline-flex; align-items: center; gap: 4px; margin-right: 12px; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.eng:last-child { margin-right: 0; }
.ic2 { width: 15px; height: 15px; stroke-width: 2; flex: 0 0 auto; }

/* ปุ่มเปิด/พักบอท (แยกเป็น 2 ปุ่มมีไอคอน) */
.pause-toggle { display: inline-flex; gap: 8px; flex: 0 0 auto; }
.pause-toggle button { font-weight: 600; }
.pause-toggle .ic { width: 16px; height: 16px; }
#pauseOnBtn.active { color: var(--ok); border-color: var(--ok); background: rgba(22,163,74,.10); }
#pauseOffBtn.active { color: var(--warn); border-color: var(--warn); background: rgba(217,119,6,.10); }

/* สินค้าที่คอมเมนต์ใต้โพสต์ (ในตารางข่าว) */
.post-aff { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 5px; font-size: 13px; color: var(--muted); }
.post-aff .ic2 { color: var(--muted); }
.post-aff a { color: var(--primary); }
.post-aff .aff-sep { color: var(--border); margin: 0 2px; }
.col-no { width: 48px; text-align: center; }
td.col-no .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--muted); font-size: 15.5px; font-weight: 700;
}
.aff-title {
  font-weight: 600; max-width: 520px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
}
/* ลิงก์ + สถานะ Live อยู่บรรทัดเดียวกัน (ไม่ตกบรรทัด) */
.link-cell { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.link-chip {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  flex: 0 0 auto;                 /* กว้างคงที่ทุกแถว → ปุ่ม "เปิด" + Live ตรงแนวกัน */
  background: var(--bg2); border: 1px solid var(--border); border-radius: 99px;
  padding: 5px 6px 5px 13px; text-decoration: none; color: var(--text);
  transition: .15s;
}
.link-chip:hover { border-color: var(--primary); }
.link-chip .link-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 15.5px; color: var(--muted); width: 240px;  /* คงที่ → ตัดข้อความเท่ากันทุกแถว */
}
.link-chip .link-open {
  flex: 0 0 auto; background: var(--primary); color: #fff;
  font-size: 14px; font-weight: 600; padding: 4px 11px; border-radius: 99px;
}
.link-chip:hover .link-open { background: var(--primary-d); }
/* สถานะลิงก์ (live / ตาย) หลังลิงก์ */
.aff-status {
  display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto;
  min-width: 120px;  /* จองพื้นที่คงที่ กันคอลัมน์ขยับตอนเปลี่ยน "กำลังตรวจ..." -> Live */
  font-size: 14px; font-weight: 600; vertical-align: middle; white-space: nowrap;
}
.aff-status.checking { color: var(--muted); font-weight: 400; }
.aff-status.live { color: var(--ok); }
.aff-status.dead { color: var(--danger); }

/* จุดเขียวเรืองแสง + วงแหวนกระพริบ (สไตล์เดียวกับ RPi Monitor) */
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); position: relative; flex-shrink: 0;
  animation: liveGlow 1.6s ease-in-out infinite;
}
.live-dot::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: var(--ok); animation: liveRing 1.6s ease-out infinite;
}
.live-dot.off { background: var(--danger); animation: none; box-shadow: 0 0 6px var(--danger); }
.live-dot.off::after { display: none; }
@keyframes liveGlow { 0%, 100% { box-shadow: 0 0 6px var(--ok); } 50% { box-shadow: 0 0 12px 2px var(--ok); } }

/* ลูกบอลในป้าย "โหมดบอล" — เด้งเบา ๆ */
.stat-note .ball { display: inline-block; animation: ballBounce 1.6s ease-in-out infinite; }
@keyframes ballBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* ── ป้าย "บอลกำลังเตะ!" — เด่น + animation ── */
.live-badge {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: 8px;
  background: linear-gradient(95deg, #16a34a, #22c55e); color: #fff;
  font-weight: 800; font-size: 14.5px; border-radius: 16px; padding: 7px 14px;
  box-shadow: 0 0 0 0 rgba(34,197,94,.55); animation: livePulse 1.5s ease-out infinite;
}
.live-badge .lb-row1 { display: inline-flex; align-items: center; gap: 7px; }
.live-badge .lb-row2 { font-weight: 800; font-size: 15px; }
.live-badge b { color: #fff; font-weight: 800; }
.live-badge .vs { opacity: .85; font-weight: 600; font-size: .9em; }
.live-badge .live-tag {
  background: #ef4444; color: #fff; font-size: 11px; font-weight: 800;
  letter-spacing: 1px; padding: 1px 7px; border-radius: 6px;
  animation: liveBlink 1s steps(1) infinite;
}
.live-badge .ball-spin { display: inline-block; font-size: 16px; animation: ballSpin 1.1s linear infinite; }
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.55); } 70% { box-shadow: 0 0 0 11px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
@keyframes ballSpin { to { transform: rotate(360deg); } }
@keyframes liveBlink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: .35; } }

/* ── การ์ด Fixtures วันนี้ ── */
.fixtures { display: flex; flex-direction: column; gap: 8px; }
.fx-row {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg2);
}
.fx-row.live { border-color: #22c55e; background: linear-gradient(95deg, rgba(34,197,94,.12), rgba(34,197,94,.03)); }
.fx-row.is-next { border-color: var(--primary); background: linear-gradient(95deg, rgba(37,99,235,.10), rgba(37,99,235,.02)); }
.fx-row.is-next .fx-time, .fx-row.is-next .fx-status { color: var(--primary); }

/* ── บล็อก "คู่ต่อไป" (เด่นด้านบนการ์ด) ── */
.fx-next {
  border: 1.5px solid var(--primary); border-radius: 12px; padding: 12px 14px;
  background: linear-gradient(135deg, rgba(37,99,235,.12), rgba(37,99,235,.03));
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 2px;
}
.fx-next-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 800; letter-spacing: .3px; color: var(--primary);
  text-transform: uppercase;
}
.fx-next-label .ic { width: 15px; height: 15px; }
.fx-next-when { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); font-weight: 700; }
.fx-next-teams { justify-content: center; gap: 14px; font-size: 16px; }
.fx-next-teams .fx-team b { font-size: 16px; }
.fx-next-teams .fx-team img { width: 26px; height: 18px; }
.fx-next-teams .fx-mid { color: var(--muted); font-size: 14px; }
.fx-next-stage { text-align: center; font-size: 12.5px; color: var(--muted); font-weight: 600; }

.fx-today-head { font-size: 13px; font-weight: 700; color: var(--muted); margin: 8px 0 -2px 2px; }
.fx-empty { font-size: 14px; color: var(--muted); padding: 16px 2px; text-align: center; }

/* ── หน้าตารางแข่งทั้งทัวร์นาเมนต์ ── */
.fx-filter { display: flex; gap: 8px; margin: 12px 0 14px; }
.fx-fbtn {
  font-size: 14px; font-weight: 600; padding: 7px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--muted); cursor: pointer;
  transition: all .18s;
}
.fx-fbtn:hover { border-color: var(--primary); color: var(--primary); }
.fx-fbtn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.fixtures-all { display: flex; flex-direction: column; gap: 8px; }
.fx-date-head {
  font-size: 14px; font-weight: 800; color: var(--primary); margin: 14px 0 4px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.fixtures-all .fx-row { grid-template-columns: 52px 1fr auto; }
.fx-right { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.fx-stage-sm { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.fx-prev-btn {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 13px; font-weight: 700; padding: 7px 13px; border-radius: 9px;
  border: 1px solid var(--primary); background: rgba(37,99,235,.08); color: var(--primary);
  cursor: pointer; transition: all .18s;
}
.fx-prev-btn:hover:not(:disabled) { background: var(--primary); color: #fff; }
.fx-prev-btn:disabled { opacity: .55; cursor: default; }
.fx-prev-btn .ic { width: 15px; height: 15px; }

/* ── การ์ดพับได้ (collapsible) — ใช้กับการ์ดตั้งค่าที่ตั้งทีเดียว ── */
.collapsible > .panel-head { cursor: pointer; }
.collapsible > .panel-head::after {
  content: ""; display: inline-block; width: 9px; height: 9px; margin-left: 10px;
  border-right: 2.5px solid var(--muted); border-bottom: 2.5px solid var(--muted);
  transform: rotate(225deg); transition: transform .2s; align-self: center; flex: 0 0 auto;
}
.collapsible.collapsed > .panel-head::after { transform: rotate(45deg); margin-top: -4px; }
.collapsible.collapsed > .panel-head { margin-bottom: 0; }
.collapsible.collapsed > *:not(.panel-head) { display: none !important; }

/* ── ข่าวถัดไปที่เตรียมไว้ (staged next post) ── */
.next-body { margin-top: 6px; }
.next-empty { font-size: 14.5px; color: var(--muted); padding: 8px 0 12px; }
.next-card { display: flex; gap: 16px; align-items: flex-start; }
.next-img {
  width: 200px; height: 132px; object-fit: cover; border-radius: 12px; flex: 0 0 auto;
  box-shadow: 0 0 0 1px var(--border);
}
.next-card-img {
  width: 240px; height: 240px; object-fit: cover;   /* การ์ดแบรนด์เป็นสี่เหลี่ยมจัตุรัส (พรีวิวจริง) */
}
.next-main { min-width: 0; flex: 1; }
.next-headline { font-size: 17px; font-weight: 800; line-height: 1.45; color: var(--text); }
.next-meta { font-size: 12.5px; color: var(--muted); margin: 4px 0 8px; }
.next-text {
  font-size: 14.5px; line-height: 1.65; color: #334155; white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow-y: auto; padding-right: 6px;
}
.next-edited { color: var(--primary); font-weight: 700; }
.next-edit-ta {
  width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-family: inherit; font-size: 14.5px; line-height: 1.65; color: var(--text);
  background: var(--bg2); resize: vertical; min-height: 160px;
}
.next-edit-ta:focus { outline: none; border-color: var(--primary); }
.next-link { margin-top: 8px; font-size: 13px; }
.next-link a { color: var(--primary); text-decoration: none; font-weight: 600; }
.next-link a:hover { text-decoration: underline; }
@media (max-width: 640px) {
  .next-card { flex-direction: column; }
  .next-img { width: 100%; height: 180px; }
  .next-card-img { width: 100%; height: auto; aspect-ratio: 1 / 1; }
}

/* ── การ์ดการใช้งาน API (usage) ── */
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-top: 6px; }
.usage-tile { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--bg2); }
.usage-top { display: flex; align-items: center; gap: 8px; }
.usage-ic { font-size: 18px; }
.usage-label { font-size: 13.5px; font-weight: 700; color: var(--muted); }
.usage-num { font-size: 30px; font-weight: 800; color: var(--text); margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.usage-bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.usage-fill { height: 100%; border-radius: 999px; background: var(--primary); transition: width .4s; }
.usage-fill.danger { background: var(--danger); }
.usage-sub { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.fx-time { font-weight: 700; color: var(--muted); font-size: 14.5px; }
.fx-row.live .fx-time { color: #16a34a; }
.fx-teams { display: flex; align-items: center; gap: 10px; min-width: 0; }
.fx-team { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.fx-team img { width: 22px; height: 15px; object-fit: cover; border-radius: 2px; flex: 0 0 auto; box-shadow: 0 0 0 1px var(--border); }
.fx-team b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-mid { font-weight: 800; color: var(--text); padding: 0 2px; flex: 0 0 auto; }
.fx-status { font-size: 13px; font-weight: 700; white-space: nowrap; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; }
.fx-status .ball-spin { font-size: 14px; }
.fx-row.live .fx-status { color: #16a34a; }
.fx-row.finished .fx-status, .fx-row.upcoming .fx-status { color: var(--muted); }
@keyframes liveRing { 0% { transform: scale(1); opacity: .6; } 100% { transform: scale(2.6); opacity: 0; } }

@media (max-width: 640px) {
  .aff-title { max-width: 120px; }
  .link-chip .link-text { width: 130px; }
  .post-title-en, .post-title-th { max-width: 150px; }
}

/* ── Run log (แยกเป็นการ์ดต่อ 1 รอบ) ── */
.runlog { display: flex; flex-direction: column; gap: 6px; max-height: 460px; overflow-y: auto; padding-right: 4px; }
.log-scope {
  flex: 0 0 auto; align-self: flex-start;
  font-size: 13px; font-weight: 700; color: var(--primary);
  background: rgba(37,99,235,.10); border: 1px solid var(--primary);
  border-radius: 999px; padding: 3px 12px; margin-bottom: 4px;
}
.run-item {
  flex: 0 0 auto;            /* กันการ์ดถูกบีบจนเนื้อหาโดนตัด/ซ้อนกัน */
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg2); overflow: hidden;
}
.run-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  cursor: pointer; font-size: 15.5px; line-height: 1.5; min-height: 22px; user-select: none;
}
.run-head:hover { background: rgba(15,23,42,.03); }
.run-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.run-item.posted .run-dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.run-item.error .run-dot { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.run-time { color: var(--muted); flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.run-status { font-weight: 600; flex: 0 0 auto; color: var(--text); }
.run-item.posted .run-status { color: var(--ok); }
.run-item.error .run-status { color: var(--danger); }
.run-item.skip .run-status { color: var(--muted); font-weight: 500; }
.run-summary { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-caret { color: var(--muted); flex: 0 0 auto; font-size: 13px; }
.run-raw {
  margin: 0; padding: 10px 12px; border-top: 1px solid var(--border);
  background: var(--bg2); color: #334155; font-size: 14.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
  font-family: inherit;
}

/* ── Fields ── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 15.5px; color: var(--muted); }
.field textarea { resize: vertical; font-family: inherit; font-size: 15.5px; line-height: 1.6; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

/* ── Preview ── */
.pv-title { font-weight: 700; margin-bottom: 6px; }
.pv-text {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; white-space: pre-wrap; line-height: 1.6; font-size: 16px;
}
.pv-link { font-size: 15.5px; margin-top: 8px; }
.pv-img { max-width: 100%; border-radius: 10px; margin-bottom: 12px; border: 1px solid var(--border); }

/* การ์ดข่าวพรีวิว (สไลด์ทีละข่าว + ปุ่มกลมเลือก 1..N) */
.pv-hint { margin-bottom: 14px; font-size: 15px; }
.pv-slider { display: flex; align-items: center; gap: 10px; }
/* viewport ครอบ track ที่เลื่อนได้แบบ smooth (translateX) + ปรับความสูงตามข่าวที่เปิด */
.pv-viewport { flex: 1; min-width: 0; overflow: hidden; transition: height .35s ease; }
.pv-track { display: flex; align-items: flex-start; transition: transform .4s cubic-bezier(.22, .61, .36, 1); }
.pv-slide { flex: 0 0 100%; min-width: 0; align-self: flex-start; }
.pv-text.pv-loading { color: var(--muted); font-style: italic; }
/* สรุปข่าวอังกฤษ (ก่อนแปล) ไว้ช่วยตัดสินใจ — clamp กันยาวเกิน */
.pv-summary {
  margin: 8px 0 4px; line-height: 1.55; font-size: 15px;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.pv-translate { font-weight: 600; }
/* ช่องแก้คำแปลก่อนโพสต์ */
.pv-text.editing { background: transparent; border: none; padding: 0; }
.pv-edit-label { font-size: 13px; margin-bottom: 6px; }
.pv-edit {
  width: 100%; background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font-family: inherit; font-size: 16px;
  line-height: 1.6; resize: vertical; min-height: 80px; overflow: hidden;
}
.pv-edit:focus { outline: none; border-color: var(--primary); }
/* ตั้งเวลาโพสต์ในพรีวิว */
.pv-sched { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.pv-sched-time {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 8px 11px; font-family: inherit; font-size: 15px;
}
.pv-sched-time:focus { outline: none; border-color: var(--primary); }
/* คอลัมน์หัวข้อในตารางคิว กินพื้นที่ที่เหลือ */
#queueTable th:nth-child(2), #queueTable td:nth-child(2) { width: 100%; }
.pv-arrow {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; line-height: 1; color: var(--muted);
  background: var(--bg2); border: 1px solid var(--border); cursor: pointer; transition: .15s;
}
.pv-arrow:hover { color: var(--primary); border-color: var(--primary); transform: scale(1.08); }
.pv-arrow:active { transform: scale(.94); }
.pv-dots { display: flex; justify-content: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.pv-dot {
  width: 36px; height: 36px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: var(--muted);
  background: var(--bg2); border: 1px solid var(--border); cursor: pointer;
  transition: transform .2s ease, background .2s ease, color .2s ease, border-color .2s ease;
}
.pv-dot:hover { border-color: var(--primary); color: var(--primary); }
.pv-dot.active { background: var(--primary); border-color: var(--primary); color: #fff; transform: scale(1.15); }
.pv-item {
  position: relative; display: flex; gap: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg2); padding: 16px; margin: 0 2px;
}
.pv-num {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 15px;
}
.pv-content { flex: 1; min-width: 0; }
.pv-item .pv-img { max-height: 280px; object-fit: cover; width: 100%; }
/* เลือกรูป: รูปย่อ + ช่องวางลิงก์รูปเอง */
.pv-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pv-thumb { padding: 0; width: 64px; height: 44px; border-radius: 8px; overflow: hidden; border: 2px solid var(--border); background: var(--bg2); cursor: pointer; }
.pv-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv-thumb.active { border-color: var(--primary); }
.pv-imgurl { display: flex; gap: 8px; margin-top: 10px; }
.pv-imgurl input { flex: 1; background: var(--bg2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 8px 11px; font-family: inherit; font-size: 14px; }
.pv-imgurl input:focus { outline: none; border-color: var(--primary); }
.pv-actions { margin-top: 14px; }
.pv-actions button { font-weight: 600; }

/* ── Pagination ── */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }
.pager-info { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }

/* ── Modal ยืนยันการลบ ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(15, 23, 42, .45); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; transition: opacity .18s ease;
}
.modal-overlay.show { opacity: 1; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(400px, 92vw); padding: 26px 24px 20px; text-align: center;
  box-shadow: 0 24px 60px -12px rgba(15, 23, 42, .35);
  transform: translateY(8px) scale(.97); transition: transform .18s ease;
}
.modal-overlay.show .modal { transform: translateY(0) scale(1); }
.modal-icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.modal-icon.tone-danger { background: rgba(225, 29, 72, .10); color: var(--danger); }
.modal-icon.tone-primary { background: rgba(37, 99, 235, .10); color: var(--primary); }
.modal-icon svg { width: 26px; height: 26px; }
.modal-title { margin: 0 0 8px; font-size: 18px; font-weight: 700; }
.modal-body { color: var(--text); font-size: 15.5px; line-height: 1.5; word-break: break-word; }
.modal-note { color: var(--muted); font-size: 14px; margin-top: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions button { flex: 1; padding: 11px 16px; font-weight: 600; }
.modal-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.modal-danger:hover { background: #be123c; border-color: #be123c; }
.modal-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.modal-primary:hover { background: var(--primary-d); border-color: var(--primary-d); }

/* ── แถบเลิกทำ (Undo) ── */
.undo-bar {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  display: flex; align-items: center; gap: 12px; z-index: 65;
  background: #0f172a; color: #f1f5f9; border-radius: 12px;
  padding: 12px 14px 12px 18px; box-shadow: 0 12px 30px rgba(15, 23, 42, .35);
  opacity: 0; transition: opacity .2s ease, transform .2s ease; max-width: 90vw;
}
.undo-bar.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.undo-ic { width: 18px; height: 18px; flex: 0 0 auto; color: #94a3b8; }
.undo-msg { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.undo-btn {
  flex: 0 0 auto; background: transparent; border: none; color: #60a5fa;
  font-weight: 700; font-size: 15px; padding: 4px 8px; cursor: pointer;
}
.undo-btn:hover { color: #93c5fd; border: none; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 20px; z-index: 60; box-shadow: 0 8px 24px rgba(15,23,42,.18);
  font-size: 16px; max-width: 90vw;
}
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--danger); }

/* ── Setup ── */
.banner {
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
  border: 1px solid var(--warn); background: rgba(217,119,6,.10); color: #92400e;
  font-size: 16px;
}
.banner.ok { border-color: var(--ok); background: rgba(22,163,74,.10); color: #166534; }
.checklist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.check-item { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.check-dot {
  width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted);
}
.check-dot.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.setup-block { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 4px; }
.block-title { font-weight: 600; font-size: 16px; margin: 12px 0 8px; }
.adv { margin-top: 12px; }
.adv summary { cursor: pointer; color: var(--muted); font-size: 15.5px; }
input[type="file"] {
  color: var(--muted); font-size: 15.5px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 7px;
}
.badge.warn { color: var(--warn); border-color: var(--warn); }

.foot { text-align: center; color: var(--muted); font-size: 14px; padding: 20px 0; }

/* ── ช่องติ๊ก (เช่น โหมดตารางแข่ง) ── */
.check-field {
  display: flex; align-items: flex-start; gap: 10px; margin: 4px 0 16px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg2);
  cursor: pointer; font-size: 15.5px; line-height: 1.5;
}
.check-field input[type="checkbox"] { width: 20px; height: 20px; margin-top: 1px; flex: 0 0 auto; accent-color: var(--primary); cursor: pointer; }

/* ── ตัวเลือกเพจมุมบน (multi-page) — เด่น เห็นชัดว่าอยู่เพจไหน ── */
.page-picker {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(37,99,235,.10); border: 1.5px solid var(--primary);
  border-radius: 12px; padding: 5px 8px 5px 12px; max-width: 520px;
}
.page-picker .ic { width: 18px; height: 18px; color: var(--primary); flex: 0 0 auto; }
.page-select {
  background: transparent; border: none; color: var(--primary);
  font-family: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
  min-width: 240px; max-width: 470px; padding: 4px 4px;
}
.page-select:focus { outline: none; }
.page-select option { color: var(--text); font-weight: 600; }

/* ── แบนเนอร์รูปโปรไฟล์เพจ ── */
.profile-banner {
  border-radius: var(--radius); overflow: hidden; margin-bottom: 16px;
  border: 1px solid var(--border); background: var(--card); box-shadow: var(--shadow-soft);
}
/* แสดงรูปเต็มความสูงตามสัดส่วนจริง (ไม่ครอป)
   aspect-ratio จองที่ไว้ล่วงหน้าตามสัดส่วนรูปจริง (1942x809) — ไม่งั้นตอนรูปยังไม่มา
   กล่องสูง 0 พอรูปโหลดเสร็จของข้างล่างถูกดันลงทีเดียว เห็นเป็นหน้ากระตุก */
.profile-banner { aspect-ratio: var(--banner-ratio, 2.4); }
.profile-banner img { width: 100%; height: auto; display: block; }

/* โครงร่างระหว่างรอรูป — แถบไล่สีวิ่งช้า ๆ พอให้รู้ว่ากำลังโหลด ไม่ดึงสายตา */
.profile-banner.loading {
  background: linear-gradient(100deg, var(--bg2) 30%, var(--border) 50%, var(--bg2) 70%);
  background-size: 220% 100%;
  animation: bannerShimmer 1.4s ease-in-out infinite;
}
.profile-banner.loading img { opacity: 0; }
.profile-banner img { transition: opacity .25s ease; }
@keyframes bannerShimmer {
  0%   { background-position: 180% 0 }
  100% { background-position: -80% 0 }
}
/* เครื่องที่ตั้งค่า "ลดการเคลื่อนไหว" ไว้ = ไม่ต้องวิ่ง แค่พื้นเทาเฉย ๆ */
@media (prefers-reduced-motion: reduce) {
  .profile-banner.loading { animation: none; }
}

/* ── พรีวิว + ปุ่มจัดการรูปโปรไฟล์ในหน้าตั้งค่าระบบ ── */
.profile-img-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 10px; }
.setup-profile-thumb {
  width: 120px; height: 120px; border-radius: 16px; object-fit: cover;
  border: 1px solid var(--border); background: var(--bg); flex: 0 0 auto;
}
.setup-profile-thumb.noimg {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; text-align: center;
  background: linear-gradient(95deg, rgba(37,99,235,.10), rgba(232,196,104,.10));
}

/* ── การ์ด "โพสต์ถัดไป" + แถบจัดการ ── */
.card-next { font-size: 19px; font-weight: 700; line-height: 1.35; margin-top: 4px; }
.manage-info { font-size: 15px; margin-bottom: 12px; }

/* ── เขียนข่าวเอง (preview รูป) ── */
.cmp-preview { margin: -6px 0 14px; }
.cmp-preview img { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--border); }

/* ── ชิปเลือกเพจของสินค้า affiliate ── */
.aff-pages { display: flex; flex-wrap: wrap; gap: 6px; max-width: 280px; }
.aff-page-chip {
  padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg2); color: var(--muted); cursor: pointer;
}
.aff-page-chip.on { background: rgba(22,163,74,.12); border-color: var(--ok); color: var(--ok); }
.aff-page-chip:hover { border-color: var(--primary); }

/* ── แก้สินค้าในคอมเมนต์ (modal log) ── */
.afflog-edit { flex: 0 0 auto; }
.afflog-select {
  flex: 1; min-width: 0; background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 9px 11px; font-family: inherit; font-size: 15px;
}
.afflog-select:focus { outline: none; border-color: var(--primary); }
.afflog-item .modal-primary { flex: 0 0 auto; }

/* ── ตารางจัดการเพจ ── */
.page-name { font-weight: 600; }
.page-folder { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-id { color: var(--muted); font-size: 14.5px; font-variant-numeric: tabular-nums; letter-spacing: .3px; }
.page-active-badge {
  display: inline-block; margin-left: 8px; padding: 2px 9px; border-radius: 99px;
  background: rgba(37,99,235,.12); color: var(--primary); font-size: 12.5px; font-weight: 700;
}
.page-active-badge.warn { background: rgba(217,119,6,.12); color: var(--warn); }

/* ── เปิด/พักบอท (หน้าตั้งค่าระบบ) ── */
.pause-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.pause-info { flex: 1; min-width: 200px; }
.pause-state { font-weight: 700; font-size: 16.5px; }
.pause-state.on { color: var(--ok); }
.pause-state.off { color: var(--warn); }

/* ── ปุ่มในคอลัมน์ "โพสต์" (ดูโพสต์ + log สินค้า) ── */
.post-actions { display: inline-flex; align-items: center; gap: 6px; }
.aff-log-btn { background: transparent; gap: 4px; position: relative; }
.aff-log-btn .ic2 { width: 17px; height: 17px; }
.aff-log-count { font-size: 13px; font-weight: 700; color: var(--primary); }

/* ── Modal แบบฟอร์ม (แก้คิว / log สินค้า) — กว้างกว่า + ชิดซ้าย ── */
.modal.modal-form { width: min(460px, 94vw); text-align: left; }
.modal.modal-form .modal-icon, .modal.modal-form .modal-title { text-align: center; }
.modal-form .field { margin-bottom: 12px; }
.modal-form input[type="datetime-local"], .modal-form textarea {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 13px; font-size: 16px; font-family: inherit; width: 100%;
  line-height: 1.6; resize: vertical;
}
.modal-form input:focus, .modal-form textarea:focus { outline: none; border-color: var(--primary); }

/* รายการสินค้าที่คอมเมนต์ (ใน modal) */
.afflog-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; margin: 6px 0 4px; }
.afflog-item {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  background: var(--bg2); color: var(--text); transition: .15s;
}
.afflog-item:hover { border-color: var(--primary); text-decoration: none; }
.afflog-ic { display: inline-flex; color: var(--muted); flex: 0 0 auto; }
.afflog-ic .ic2 { width: 18px; height: 18px; }
.afflog-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.afflog-title { font-weight: 600; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.afflog-link { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.afflog-open { flex: 0 0 auto; background: var(--primary); color: #fff; font-size: 13px; font-weight: 600; padding: 4px 11px; border-radius: 99px; }

/* ════════════ Responsive: แท็บเล็ต (iPad Pro 11") ════════════ */
@media (max-width: 1024px) {
  #appWrap { padding: 14px 18px 40px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .post-title-en, .post-title-th { max-width: 420px; }
  .aff-title { max-width: 360px; }
  .link-chip .link-text { width: 180px; }
}

/* ════════════ Responsive: มือถือจอใหญ่ (iPhone 17 Pro Max, S26 Ultra) ════════════ */
@media (max-width: 720px) {
  html { font-size: 15px; }
  #appWrap { padding: 12px 12px 36px; }
  .topbar { padding: 6px 2px 14px; }
  .title { font-size: 18.5px; }
  .server-time { font-size: 13.5px; }
  .nav { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-tab { padding: 9px 11px; font-size: 14.5px; white-space: nowrap; flex: 0 0 auto; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 13px; }
  .card-big { font-size: 30px; }
  .panel { padding: 13px; }
  .btn-row { gap: 8px; }
  .btn-row button { flex: 1 1 auto; }
  .tbl thead th, .tbl tbody td { padding: 10px 9px; }
  table, .tbl { font-size: 15px; }
  /* ตารางเลื่อนแนวนอนได้ในจอแคบ แทนการบีบจนอ่านไม่ออก */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .post-title-en, .post-title-th { max-width: 230px; }
  .aff-title { max-width: 200px; }
  .pause-row { flex-direction: column; align-items: stretch; }
  .pause-toggle { width: 100%; }
  .pause-toggle button { flex: 1; }
  .pv-slider { gap: 4px; }
  .pv-arrow { width: 34px; height: 34px; font-size: 20px; }
  .pv-item { padding: 12px; gap: 10px; }
  .modal.modal-form { width: 94vw; }
}

/* ════════════ Responsive: มือถือจอเล็ก ════════════ */
@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .card-big { font-size: 26px; }
  .pv-num { display: none; }
}

/* ════════════ ป้ายชื่อเพจบนหัวตั้งค่า + หัวกลุ่มตั้งค่าเฉพาะเพจบอล ════════════ */
.page-badge {
  margin-left: auto; font-size: 13px; font-weight: 700; color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  padding: 3px 12px; border-radius: 999px; white-space: nowrap;
}
.settings-group-label {
  margin: 16px 0 6px; padding-top: 14px; border-top: 1px solid var(--border);
  font-weight: 800; font-size: 13.5px; color: var(--muted); letter-spacing: .3px;
}

/* ── กระดิ่งแจ้งเตือนลิงก์สินค้าตาย (สไตล์ FixPay) ── */
.bell-wrap { position: relative; display: inline-flex; }
.bell-btn { position: relative; }
.bell-wrap.has-alert .bell-btn { color: var(--danger); }
.bell-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 17px; height: 17px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 800; line-height: 1;
  border-radius: 999px; border: 2px solid var(--card);
}
.bell-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  width: 340px; max-width: calc(100vw - 24px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-soft);
  overflow: hidden;
  animation: bellIn .14s ease;
}
@keyframes bellIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.bell-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.bell-title { font-weight: 800; font-size: 15px; color: var(--text); }
.bell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bell-rescan.spinning .ic, #bellRescan.spinning .ic { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bell-list { max-height: 360px; overflow-y: auto; }
.bell-empty { padding: 26px 14px; text-align: center; color: var(--muted); font-size: 14px; }
.bell-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; text-align: left; background: none; border: none;
  border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 0;
}
.bell-item:last-child { border-bottom: none; }
.bell-item:hover { background: var(--bg2); border-color: var(--border); }
.bell-ic {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
}
.bell-ic svg { width: 16px; height: 16px; }
.bell-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.bell-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bell-reason { font-size: 12px; color: var(--danger); }

/* ── PIN pad (หน้า login) ── */
.login-logo {
  width: 68px; height: 68px; margin: 0 auto 4px; border-radius: 18px;
  display: grid; place-items: center; background: var(--bg2); border: 1px solid var(--border);
}
.login-logo img { border-radius: 12px; display: block; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 6px 0 2px; }
.pin-dots.shake { animation: pinShake .4s; }
.pin-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--bg2);
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.pin-dot.on {
  background: var(--primary); border-color: var(--primary);
  box-shadow: 0 0 10px rgba(37, 99, 235, .45);
}
@keyframes pinShake {
  0%, 100% { transform: translateX(0) }
  20%, 60% { transform: translateX(-8px) }
  40%, 80% { transform: translateX(8px) }
}
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 4px; }
.pin-key {
  font-family: var(--font-mono); font-size: 1.5rem; padding: 16px 0;
  cursor: pointer; background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  transition: transform .06s, border-color .15s, color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.pin-key:hover { border-color: var(--primary); color: var(--primary); }
.pin-key:active { transform: scale(.94); background: rgba(37, 99, 235, .1); }
.pin-key.pin-fn { font-size: 1.1rem; color: var(--muted); }
.pin-key:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ── โครงร่างระหว่างโหลดข้อมูลรอบแรก ─────────────────────────────────
   เดิมหน้าเปิดมาโชว์ค่าว่าง (0/4, —, ตารางเปล่า) แล้วค่อยเด้งเป็นค่าจริง
   ทำให้รู้สึกวิบวับ · ตอนนี้โชว์เป็นแถบเทาไล่สีจนกว่าข้อมูลจริงจะมา
   ทุกช่องคงขนาดเดิมไว้ ค่าจริงมาแล้วแทนที่ในตำแหน่งเดิม ไม่ดันอะไร */
@keyframes skelShimmer {
  0%   { background-position: 180% 0 }
  100% { background-position: -80% 0 }
}
.skel-base {
  background-image: linear-gradient(100deg, var(--bg2) 30%, var(--border) 50%, var(--bg2) 70%);
  background-size: 220% 100%;
  animation: skelShimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}
#appWrap.is-booting .skel-on {
  background-image: linear-gradient(100deg, var(--bg2) 30%, var(--border) 50%, var(--bg2) 70%);
  background-size: 220% 100%;
  animation: skelShimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
  color: transparent !important;
}
/* ซ่อนลูกใน (จุดสถานะ/เส้นทับ) ไม่ให้โผล่ทะลุแถบเทา */
#appWrap.is-booting .skel-on * { visibility: hidden; }
/* การ์ดตัวเลขใหญ่ให้แถบกว้างพอดูเป็นก้อน ไม่ใช่ขีดจิ๋วตามความกว้างตัวเลข */
#appWrap.is-booting .card-big.skel-on { min-width: 108px; }
#appWrap.is-booting .badges.skel-on { min-height: 62px; }
#appWrap.is-booting .progress-fill { background: transparent; }

/* แถวโครงร่างของตาราง */
#postsSkel { display: none; }
#appWrap.is-booting #postsSkel { display: table-row-group; }
#appWrap.is-booting #postsBody { display: none; }
.skel-line {
  display: inline-block; height: 12px; border-radius: 6px; vertical-align: middle;
  background-image: linear-gradient(100deg, var(--bg2) 30%, var(--border) 50%, var(--bg2) 70%);
  background-size: 220% 100%;
  animation: skelShimmer 1.4s ease-in-out infinite;
}
.skel-line.w-xs { width: 28px }
.skel-line.w-sm { width: 64px }
.skel-line.w-lg { width: min(340px, 60vw) }

@media (prefers-reduced-motion: reduce) {
  .skel-base, .skel-line, #appWrap.is-booting .skel-on { animation: none; }
}

/* โครงร่าง "ข่าวถัดไปที่เตรียมไว้" — ทรงเดียวกับ .next-card ของจริง
   (รูป 200x132 + บรรทัดข้อความ) เพื่อให้ความสูงตรงกันตั้งแต่ยังไม่มีข้อมูล */
.next-skel-text { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; flex: 1 1 auto; }
.next-skel-text .skel-line { height: 14px; }
.next-skel-msg { font-size: 14px; margin-bottom: 2px; }
/* โครงร่างใช้คลาสเดียวกับรูปจริง (.next-card-img) จุดตัดจอจึงต้องตรงกับของจริงที่ 640px
   ไม่งั้นช่วง 640-720px จะจองผิดขนาดแล้วกระตุกตอนของจริงมา */
@media (max-width: 640px) {
  .next-skel { flex-direction: column; }
}

/* โครงร่างการ์ดโปรแกรมแข่ง (สูงใกล้เคียงรายการจริง) */
.fx-skel { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 2px; }
.fx-skel .skel-line { height: 14px; }
