/* Dashboard ยอดขาย × แอด (Phase 4) — ใช้ token สีจาก style.css เดิม */
:root {
  --s-sales: #D97706;   /* เส้นยอดขาย (อำพันเข้ม) — ผ่านตรวจตาบอดสีคู่กับฟ้า */
  --s-metric: #0284C7;  /* เส้นตัวเลขแอด (ฟ้า) */
  --conf-hi: #22A05C; --conf-hi-bg: rgba(34, 160, 92, .13);
  --conf-md: #B45309;  --conf-md-bg: rgba(245, 158, 11, .16);
  --conf-lo: #5A6472;  --conf-lo-bg: rgba(122, 133, 148, .16);
}
@media (prefers-color-scheme: dark) {
  :root { --conf-hi: #3FBF72; --conf-md: #F6AD2B; --conf-lo: #939EAD; }
}

.dash-body { overflow: auto; }
.dash-wrap { max-width: 1080px; margin: 0 auto; padding: 18px 16px 60px; display: flex; flex-direction: column; gap: 14px; }

.dash-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.dash-top h1 { font-size: 20px; margin: 0; flex: 1; }
.dash-back { color: var(--muted); text-decoration: none; font-size: 13.5px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.dash-back:hover { color: var(--ink); }
.dash-sync { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dash-syncnote { font-size: 12px; color: var(--muted); max-width: 260px; }

.dash-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.dash-sechead { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.dash-sechead h2 { font-size: 15.5px; margin: 0; }
.dash-row { display: flex; align-items: center; gap: 8px; }
.dash-row.wrap { flex-wrap: wrap; }
.dash-row.gap { margin-top: 10px; }
.dash-flex { flex: 1; }
.grow { flex: 1; min-width: 160px; }

.dbtn { font-size: 13.5px; font-weight: 600; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.dbtn:hover { border-color: var(--accent); }
.dbtn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.dbtn.ghost { background: transparent; }
.dbtn:disabled { opacity: .5; cursor: default; }
.dsel, .dinp { font-size: 13.5px; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }

.chipset { display: flex; gap: 6px; flex-wrap: wrap; }
.chip2 { font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.chip2.on { background: var(--side-bg); color: #FFD98A; border-color: var(--side-bg); font-weight: 600; }
.chip2.soon { border-style: dashed; cursor: default; opacity: .65; }

.dash-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 10px; }
.dtile { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 12px 14px; }
.dtile .k { font-size: 12px; color: var(--muted); }
.dtile .v { font-size: 20px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.dtile .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dtile.hero { border-color: var(--accent); background: var(--accent-soft); }

.dash-scroll { overflow-x: auto; }
.dtable { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 560px; }
.dtable th { color: var(--muted); font-weight: 600; font-size: 12px; text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.dtable td { padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dtable tr:last-child td { border-bottom: none; }
.dtable .r { text-align: right; }
.dtable input.cell { width: 92px; text-align: right; font-variant-numeric: tabular-nums; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.dtable input.cell:hover:not(:disabled) { border-color: var(--accent); }
.dtable input.cell:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); background: var(--surface); }
/* ช่องที่ยังว่าง = งานค้าง — ขีดเส้นประให้เห็นว่า "พิมพ์ตรงนี้ได้" */
.dtable input.cell:placeholder-shown:not(:disabled) { border-style: dashed; border-color: var(--accent); background: var(--accent-soft); }
.dtag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; white-space: nowrap; margin-right: 4px; }
.dtag.ev { background: var(--conf-lo-bg); color: var(--muted); font-weight: 500; }
.dash-weeklabel { font-size: 13.5px; font-weight: 700; min-width: 175px; text-align: center; }
.dash-status { font-size: 12.5px; color: var(--ok); }
.dash-note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.dash-mut { font-size: 12.5px; color: var(--muted); }

.dash-details summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted); margin-top: 12px; }
.dash-evlist { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.dash-evrow { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 5px 8px; border-radius: 8px; background: var(--surface-2); }
.dash-evrow .x { margin-left: auto; color: var(--danger); cursor: pointer; font-size: 12px; }

.dash-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin: 10px 0 6px; }
.dash-legend b { color: var(--ink); font-weight: 600; }
.sw2 { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

.dash-chartwrap { position: relative; }
#chart { display: block; width: 100%; height: auto; min-height: 180px; }
.dash-tip { position: absolute; pointer-events: none; background: var(--side-bg); color: #E7ECF4; font-size: 12px; line-height: 1.5; padding: 8px 11px; border-radius: 9px; box-shadow: var(--shadow); max-width: 230px; z-index: 5; }
.dash-tip b { color: #FFD98A; }

.dash-lag { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.dash-lag input[type=range] { flex: 1; min-width: 180px; accent-color: var(--accent); }
.dash-lag b { color: var(--ink); font-size: 14.5px; min-width: 52px; }

.rbar { position: relative; height: 9px; border-radius: 5px; background: var(--conf-lo-bg); width: 110px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.rbar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; background: var(--s-sales); }
.rbar.neg i { background: var(--s-metric); }
.pill2 { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill2.hi { background: var(--conf-hi-bg); color: var(--conf-hi); }
.pill2.md { background: var(--conf-md-bg); color: var(--conf-md); }
.pill2.lo { background: var(--conf-lo-bg); color: var(--conf-lo); }

.dash-insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.dinsight { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 14px; font-size: 13.5px; }
.dinsight b { display: block; margin-bottom: 3px; }
.dinsight p { margin: 0; color: var(--muted); }

.dash-teasers { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.dash-teaser { border: 1.5px dashed var(--line); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.dash-teaser b { color: var(--ink); }

/* ---------- แท็บ + ครีเอทีฟ (Phase 5) ---------- */
.dash-tabs { display: flex; gap: 8px; }
.dash-tab { font-size: 14px; font-weight: 700; padding: 8px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.dash-tab.on { background: var(--side-bg); color: #FFD98A; border-color: var(--side-bg); }

.cr-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cr-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cr-thumb { height: 130px; background: var(--side-bg); display: flex; align-items: center; justify-content: center;
  font-size: 34px; position: relative; overflow: hidden; }
.cr-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cr-thumb small { position: absolute; bottom: 6px; right: 8px; font-size: 10.5px;
  background: rgba(0,0,0,.6); color: #fff; padding: 2px 7px; border-radius: 999px; }
.cr-body { padding: 10px 12px; font-size: 12.5px; display: flex; flex-direction: column; gap: 6px; }
.cr-body b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; margin: 1px 2px 1px 0; }
.cr-kpi { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 12px; }
.cr-brief { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; font-size: 13px; white-space: pre-wrap; font-family: inherit; line-height: 1.7; }

/* ลิงก์เดือนในตารางเฉลี่ยรายเดือน — สีน้ำเงินเดิมจมกับพื้นมืด ใช้สีทองของธีมแทน */
.mlink { color: var(--accent); text-decoration: underline dotted; text-underline-offset: 3px; }
.mlink:hover { text-decoration-style: solid; filter: brightness(1.15); }

/* ---------- แท็บ 🛒 Online & ทดลอง (Phase 6) ---------- */
.dbtn.xs { font-size: 12px; padding: 4px 10px; border-radius: 7px; }
.ol-badge { display: inline-block; min-width: 17px; text-align: center; font-size: 10.5px; font-weight: 800;
  background: #DC2626; color: #fff; border-radius: 999px; padding: 1px 5px; vertical-align: top; }
.ol-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.ol-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 13px; display: flex; flex-direction: column; gap: 7px; }
.ol-card .hd { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13.5px; }
.ol-card .hd .st { margin-left: auto; }
.ol-card p { margin: 0; }
.ol-event { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); padding: 10px 12px; font-size: 13px; margin-bottom: 8px; }
.ol-event > span { font-size: 18px; }
.ol-event > div:first-of-type { flex: 1; }
.ol-form { border: 1px dashed var(--accent); border-radius: 10px; padding: 12px; margin-bottom: 12px; background: var(--accent-soft); }
.ol-steps { margin: 4px 0 0; padding-left: 20px; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.ol-settings summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.ol-modal { position: fixed; inset: 0; z-index: 100; background: rgba(10, 16, 28, .55);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.ol-modal.hidden { display: none; }
.ol-modal-box { background: var(--surface); border: 2px solid var(--accent); border-radius: 14px;
  padding: 18px 20px; max-width: 480px; width: 100%; box-shadow: 0 18px 50px rgba(0, 0, 0, .35); }
.ol-modal-box h3 { margin: 0 0 8px; font-size: 16px; }
.ol-modal-box p { margin: 0 0 10px; font-size: 14px; }

@media (max-width: 640px) {
  .dash-top h1 { font-size: 17px; }
  .dtile .v { font-size: 17px; }
}

/* ---------- เฟสย้ายงบรายตำแหน่ง ---------- */
.pm-confirm { border: 1.5px solid var(--danger); border-radius: 12px; padding: 12px 14px; margin-top: 10px; font-size: 13.5px; line-height: 1.6; }
.pm-confirm .pm-warn { color: var(--danger); font-weight: 600; }
.pm-hist-row { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12.5px; margin-top: 6px; flex-wrap: wrap; }
.pm-hist-row .ok { color: var(--ok); font-weight: 700; }
.pm-hist-row .fail { color: var(--danger); font-weight: 700; }
.pm-pos { display: inline-block; background: var(--surface-2); border-radius: 6px; padding: 1px 7px; font-size: 11px; margin: 1px 2px 1px 0; white-space: nowrap; }

/* ---------- P9: Adstock + Backtest ---------- */
.as-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 10px; }
.as-card h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.as-big { font-size: 21px; font-weight: 800; }
.as-verdict { margin-top: 8px; font-size: 13.5px; line-height: 1.55; background: var(--surface-2); border-radius: 10px; padding: 9px 12px; }
.as-win { background: var(--ok-soft); font-weight: 700; }
.as-subhead { margin-top: 14px; font-size: 14px; }

/* ═══ P11: โทนใหม่เฉพาะหน้า Dashboard (โหมดมืด) — อ่อนขึ้นหนึ่งสเต็ป แยกจากพื้น macOS (CEO อนุมัติ 15 ก.ค.) ═══ */
@media (prefers-color-scheme: dark) {
  body.dash-body {
    --bg: #232E42; --surface: #2C3950; --surface-2: #364562;
    --ink: #EDF2FA; --muted: #9DB0CF; --line: #40506E;
    --accent-soft: #43405B;
  }
}

/* ═══ P11: ช่องคุย AI ประจำหน้า Dashboard — ปักหมุดล่างจอ ═══ */
.dash-wrap { padding-bottom: 120px; } /* กันช่องคุยบังตารางท้ายสุด */
.dchat { position: fixed; left: 50%; transform: translateX(-50%); bottom: 12px; width: min(760px, calc(100vw - 24px));
  background: var(--surface); border: 1.5px solid var(--accent); border-radius: 16px; z-index: 60;
  box-shadow: 0 -4px 28px rgba(5, 10, 20, .45); overflow: hidden; }
.dchat-msgs { max-height: 44vh; overflow-y: auto; padding: 12px 14px 4px; display: flex; flex-direction: column; gap: 8px; }
.dchat-msgs.hidden { display: none; }
.dcm { max-width: 84%; font-size: 13.5px; line-height: 1.6; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.dcm.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); font-weight: 600; border-bottom-right-radius: 4px; }
.dcm.ai { align-self: flex-start; background: var(--surface-2); color: var(--ink); border-bottom-left-radius: 4px; }
.dcm.sys { align-self: center; background: none; color: var(--muted); font-size: 11.5px; padding: 0; }
.dcm.err { align-self: center; background: rgba(214, 69, 69, .15); color: #f28b8b; font-size: 12.5px; }
.dchat-ctx { font-size: 11px; color: var(--muted); padding: 0 14px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dchat-in { display: flex; gap: 8px; align-items: center; padding: 9px 10px; }
.dchat-in input { flex: 1; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 10px; padding: 9px 14px; font-size: 13.5px; outline: none; }
.dchat-in input:focus { border-color: var(--accent); }
.dchat-btn { border: none; background: var(--accent); color: var(--accent-ink); border-radius: 10px;
  padding: 8px 14px; font-weight: 800; font-size: 14px; cursor: pointer; }
.dchat-btn:disabled { opacity: .6; }
.dchat-min { border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; cursor: pointer; }

/* P11.2: แนบไฟล์/ภาพในช่องคุย AI ของ dashboard */
.dchat-tray { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.dchat-file { font-size: 12px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; color: var(--ink); white-space: nowrap; }
.dchat-file .dchat-x { cursor: pointer; color: var(--danger); margin-left: 2px; }
.dchat-btn.ghost { background: transparent; border: none; font-size: 16px; cursor: pointer; }

/* P11.4: แถบสถานะสด — เห็นว่า AI กำลังทำอะไร ไม่ใช่ค้าง */
.dchat-status { display: flex; align-items: center; gap: 8px; padding: 6px 14px; font-size: 12.5px; color: var(--muted); }
.dchat-status .spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: dchatspin .8s linear infinite; flex: none; }
@keyframes dchatspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .dchat-status .spin { animation: none; } }
