/* Dashboard แบบ bento: การ์ดหลายขนาด ลากจัดวางใหม่ได้
 * ขนาดการ์ด (data-size): sm = 1x1, wide = 2x1, tall = 1x2, lg = 2x2  (บนจอเล็กทุกการ์ดเต็มความกว้าง)
 * ปรับหน้าตา: แก้ตัวแปรใน :root ด้านล่าง หรือคลาสของแต่ละส่วน — ไม่มี build step */
/* สี --on-strong / --series-1 / --widget-radius ตั้งไว้ที่ css/base.css (โทเคนกลาง) */
:root {
  --track: color-mix(in srgb, var(--text) 10%, transparent);
  --soft: color-mix(in srgb, var(--text) 28%, transparent);
}

/* ---------- กริด ---------- */
.board { position: relative; display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); grid-auto-flow: dense; }
@media (min-width: 600px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: minmax(200px, auto); }
  .w[data-size="wide"], .w[data-size="lg"] { grid-column: span 2; }
  .w[data-size="tall"], .w[data-size="lg"] { grid-row: span 2; }
}
@media (min-width: 900px) { .board { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.w { position: relative; min-width: 0; border-radius: var(--widget-radius); outline: none; }
.board.editable .w { cursor: grab; touch-action: pan-y pinch-zoom; -webkit-touch-callout: none; }
.w:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.w.is-lifted { z-index: 30; cursor: grabbing; }
.w.is-lifted .w-card { transform: scale(1.04); box-shadow: 0 28px 60px -16px rgb(0 0 0 / 40%), 0 10px 24px -8px rgb(0 0 0 / 25%); }
.w.is-holding .w-card { transform: scale(.97); }
.w.is-landed .w-card { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
body.dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }

.w-card {
  height: 100%; display: flex; flex-direction: column; gap: 14px; padding: 18px;
  container-type: inline-size;
  background: var(--surface); color: var(--text); border-radius: var(--widget-radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .3s cubic-bezier(.16, 1, .3, 1), box-shadow .3s, border-color .3s;
}
/* hover ยกการ์ดเล็กน้อย (เฉพาะอุปกรณ์ที่มีเมาส์ และเมื่ออนุญาตให้มีการเคลื่อนไหว) */
@media (hover: hover) {
  html.fx .board .w:not(.is-lifted):hover .w-card { transform: translateY(-3px); box-shadow: var(--shadow-lift); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
}
@media (min-width: 600px) { .w-card { padding: 24px; } }
@media (prefers-reduced-motion: reduce) { .w-card { transition: none; } }

.w-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; line-height: 1.2; }
.w-head h3 { margin: 0; font: 500 .75rem/1.2 var(--font-mono); letter-spacing: .05em; color: var(--text-2); text-transform: uppercase; }
.w-tools { display: inline-flex; align-items: center; gap: 8px; }
.w-meta { font-size: .8125rem; color: var(--text-2); }
.w-expand {
  appearance: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); background: transparent; color: var(--text-2); font-size: 1rem; line-height: 1; cursor: pointer;
  transition: background-color .2s, color .2s, transform .25s cubic-bezier(.16, 1, .3, 1);
}
@media (hover: hover) { .w-expand:hover { background: var(--surface-2); color: var(--text); transform: scale(1.08); } }
.w-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.push { margin-top: auto; }
.xcard { container-type: inline-size; display: flex; flex-direction: column; gap: 14px; }

/* ---------- ตัวเลขใหญ่ / การเปลี่ยนแปลง / จุดสถานะ ---------- */
.big { margin: 0; font: 500 2.125rem/1.1 var(--font-serif); letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.big small { font-size: .8125rem; font-weight: 400; color: var(--text-2); letter-spacing: 0; }
.hint { margin: 6px 0 0; font-size: .8125rem; color: var(--text-3); }
.delta { font-size: .875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.ok { color: var(--good); }
.delta.err { color: var(--danger); }
.delta.flat { color: var(--text-2); }
.delta-suffix { color: var(--text-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--soft); }
.dot.ok { background: var(--good); }
.dot.warn { background: #eda100; }
.dot.err { background: var(--danger); }

/* แถว "ชื่อ ....... ค่า" */
.rows { margin: 0; display: grid; gap: 8px; }
.rows .r { display: flex; align-items: center; gap: 8px; font-size: .8125rem; min-width: 0; }
.rows dt { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows dd { margin: 0 0 0 auto; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* แถบเปรียบเทียบบางๆ */
.bars { display: grid; gap: 4px 12px; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) auto; align-items: center; font-size: .8125rem; }
.bars > .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars > .v { color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; padding: 5px 0; }
.bars > .n, .bars > .t { padding: 5px 0; }
@container (max-width: 360px) { .bars { grid-template-columns: minmax(0, 6.5rem) minmax(0, 1fr) auto; } }
.hbar { display: block; height: 3px; border-radius: 999px; background: var(--track); overflow: hidden; }
.hbar > i { display: block; height: 100%; border-radius: 999px; background: var(--soft); }
.hbar.hot > i { background: var(--series-1); }

/* แท่งสั้นๆ รายวัน */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 40px; }
.spark > i { flex: 1; border-radius: 999px; background: var(--soft); min-height: 3px; }
.spark > i.hot { background: var(--series-1); }

/* ---------- minimap: 7 วัน x 24 ชั่วโมง ---------- */
.minimap { display: grid; gap: 3px 10px; grid-template-columns: minmax(0, 1fr); align-items: center; }
.minimap .day { display: none; font-size: .75rem; color: var(--text-2); line-height: 1; }
.minimap .day.today { color: var(--text); font-weight: 600; }
.minimap .cells { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 3px; }
.minimap .cells > i { aspect-ratio: 1; border-radius: 2.5px; background: color-mix(in srgb, var(--text) 6%, transparent); }
.minimap .cells > i.l1 { background: color-mix(in srgb, var(--series-1) 20%, transparent); }
.minimap .cells > i.l2 { background: color-mix(in srgb, var(--series-1) 35%, transparent); }
.minimap .cells > i.l3 { background: color-mix(in srgb, var(--series-1) 55%, transparent); }
.minimap .cells > i.l4 { background: color-mix(in srgb, var(--series-1) 85%, transparent); }
.minimap .cells > i.future { background: transparent; box-shadow: inset 0 0 0 1px var(--track); }
.minimap .cells > i.now { outline: 2px solid var(--text); outline-offset: 1px; }
.minimap .hours { display: none; grid-template-columns: repeat(4, 1fr); font-size: .75rem; color: var(--text-2); margin-top: 6px; }
@container (min-width: 440px) {
  .minimap { grid-template-columns: auto minmax(0, 1fr); }
  .minimap .day, .minimap .hours { display: block; }
  .minimap .hours { display: grid; }
}

/* ---------- เปรียบเทียบสาขาด้วยดาวรวม ---------- */
.bstars { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; overflow-y: auto; min-height: 0; }
.bstars li { display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) auto; grid-template-areas: "rank who score" ". mini mini"; gap: 2px 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.bstars li:last-child { border-bottom: 0; }
.bstars .rank { grid-area: rank; font: 600 .8125rem/1 var(--font-mono); color: var(--text-3); text-align: center; }
.bstars li:nth-child(-n+3) .rank { color: var(--accent-ink); }
.bstars .who { grid-area: who; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.bstars .who b { font-weight: 600; font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bstars .who span { font-size: .75rem; color: var(--text-3); }
.bstars .score { grid-area: score; display: inline-flex; align-items: center; gap: 8px; }
.bstars .score > b { font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; }
.bstars li.low .score > b::after { content: " ⚠"; font-size: .75rem; }
.bstars .mini { grid-area: mini; }
.bstars .mini .dist-bar { height: 8px; border-radius: 4px; }
.bstars .mini .dist-bar > span { font-size: 0; }
.star-meter { position: relative; display: inline-block; font-size: 1rem; line-height: 1; letter-spacing: 1px; color: var(--track); white-space: nowrap; }
.star-meter > i { position: absolute; inset: 0 auto 0 0; overflow: hidden; color: var(--score-3); font-style: normal; }
.w[data-widget-id="branches"] .w-body { min-height: 0; overflow-y: auto; }

/* ---------- ตารางสาขา x หัวข้อ (heatmap) ---------- */
.bgrid { display: grid; grid-template-columns: minmax(0, 1.7fr) repeat(var(--cols, 4), minmax(34px, 1fr)); gap: 4px; align-items: stretch; font-size: .8125rem; }
.bgrid .h { font-size: .6875rem; line-height: 1.25; color: var(--text-2); text-align: center; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; align-self: end; padding-bottom: 4px; }
.bgrid .name { min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.25; }
.bgrid .name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bgrid .name span { color: var(--text-3); font-size: .75rem; }
.bgrid .c {
  display: grid; place-items: center; min-height: 40px; border-radius: 8px; font-weight: 600; font-variant-numeric: tabular-nums; position: relative;
  background-color: color-mix(in srgb, var(--series-1) calc(8% + var(--t, 0) * 34%), var(--surface));
  background-image: linear-gradient(var(--series-1), var(--series-1)); background-repeat: no-repeat; background-position: left bottom; background-size: calc(var(--t, 0) * 100%) 3px;
}
.bgrid .c.low::after { content: "⚠"; position: absolute; top: 1px; right: 3px; font-size: .625rem; }
.bgrid .c.none { color: var(--text-3); font-weight: 400; }
.w[data-widget-id="branches"] .w-body { overflow-x: auto; }

/* ---------- ข้อเสนอแนะ ---------- */
.clist { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; overflow-y: auto; min-height: 0; max-height: 26rem; }
.clist .meta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: .75rem; color: var(--text-2); margin-bottom: 2px; }
.clist .meta b { color: var(--text); font-weight: 600; }
.clist .text { margin: 0; font-size: .875rem; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.stars-inline { color: var(--star); letter-spacing: 1px; }
.ch-tag { padding: 0 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

details.table-view { margin-top: 10px; }
details.table-view summary { cursor: pointer; color: var(--text-2); font-size: .8125rem; min-height: 28px; }
details.table-view table { font-size: .8125rem; }
details.table-view .table-wrap { max-height: 14rem; overflow: auto; }

/* ---------- การกระจายคะแนนรายหัวข้อ: แถบซ้อน 5★ (เขียว) → 1★ (แดง) สีจาก --score-* ใน base.css ---------- */
.dist-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .75rem; color: var(--text-2); }
.dist-legend span { display: inline-flex; align-items: center; gap: 5px; }
.dist-legend i { width: 10px; height: 10px; border-radius: 3px; }
.dist { display: grid; gap: 12px; }
.dist-groups { display: grid; gap: 18px; }
.dist-group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); font-size: .875rem; }
.dist-group-head b { font-weight: 600; color: var(--accent-ink); }
.dist-group-head span { color: var(--text-2); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.dist-head { display: flex; justify-content: space-between; gap: 10px; font-size: .8125rem; margin-bottom: 5px; }
.dist-head .n { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.dist-head .v { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dist-bar { display: flex; gap: 2px; height: 22px; border-radius: 6px; overflow: hidden; background: var(--track); }
.dist-bar > span {
  flex: 0 0 auto; min-width: 3px; display: grid; place-items: center; overflow: hidden;
  font: 600 .6875rem/1 var(--font); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.s5 { background: var(--score-5); color: var(--score-ink-light); }
.s4 { background: var(--score-4); color: var(--score-ink-dark); }
.s3 { background: var(--score-3); color: var(--score-ink-dark); }
.s2 { background: var(--score-2); color: var(--score-ink-dark); }
.s1 { background: var(--score-1); color: var(--score-ink-light); }
table.dist-table td.num, table.dist-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.dist-table th .dist-chip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
table.dist-table td small { color: var(--text-3); margin-left: 4px; }

.empty-note { color: var(--text-2); font-size: .875rem; }
.ok-note { color: var(--good); font-weight: 600; font-size: .875rem; }

/* ---------- มุมมองขยายในโมดอล ---------- */
.sort-btn { appearance: none; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; padding: 0; white-space: nowrap; }
.sort-btn:hover { color: var(--accent-ink); }
table.heat td.cell {
  text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 84px; vertical-align: middle;
  background-color: color-mix(in srgb, var(--series-1) calc(8% + var(--t, 0) * 34%), var(--surface));
  background-image: linear-gradient(var(--series-1), var(--series-1)); background-repeat: no-repeat; background-position: left bottom; background-size: calc(var(--t, 0) * 100%) 3px;
}
table.heat td.cell.low::after { content: " ⚠"; }
table.heat td.cell.none { color: var(--text-3); font-weight: 400; }
.clist.full { max-height: none; margin-top: 14px; }
.clist.full .text { display: block; -webkit-line-clamp: unset; }
.xcard .seg { margin-bottom: 4px; }
.clist li { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.clist li:last-child { border-bottom: 0; padding-bottom: 0; }
