/* =====================================================================
   หน้าแดชบอร์ด (/dashboard) — ใช้โครง .fit ของ fit.css
   รอบ 98: ทั้งหน้าเลื่อนตามปกติ (ไม่บีบให้พอดีจอแล้ว — เดิมเมื่อมีการ์ดร้านอาหาร/KPI/เริ่มต้นใช้งานอยู่ข้างบน
   การ์ดล่างถูกตัดครึ่ง หรือเหลือกรอบเลื่อนเตี้ย ๆ) · การ์ดสูงตามเนื้อหา กราฟมีความสูงขั้นต่ำของตัวเอง
   จอคอม: การ์ด 2 คอลัมน์ (≥1500px = 3 คอลัมน์)
   มือถือ: ตัวเลข 2×2 การ์ดเรียงลงมา กราฟเต็มความกว้าง (ห้ามเลื่อนข้าง)
   สีทั้งหมดใช้ตัวแปร (--brand, --surface, --line, --muted ...) เพื่อให้โหมดมืดใช้ได้เลย
   ===================================================================== */

@media screen {
  /* ---------- หัวหน้า ---------- */
  .dash-tools { gap: 8px; }
  .dash-seg {
    display: inline-flex; align-items: stretch; gap: 2px; padding: 3px; min-height: 42px;
    border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  }
  .dash-seg button {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-width: 0; padding: 4px 12px; border: 0; border-radius: 9px; background: none;
    color: var(--muted); font: inherit; font-size: .88rem; font-weight: 600; white-space: nowrap; cursor: pointer;
  }
  .dash-seg button:hover { color: var(--ink); background: var(--chip); }
  .dash-seg button.on { background: var(--brand); color: var(--brand-ink); }
  .dash-seg button small { font-size: .78rem; font-weight: 500; opacity: .8; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
  .dash-refresh { display: inline-grid; place-items: center; width: 42px; min-height: 42px; padding: 0; }
  .dash-refresh.is-busy svg { animation: dash-spin .9s linear infinite; }
  @keyframes dash-spin { to { transform: rotate(360deg); } }
  .dash-pos-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; }
  .dash-rep-btn { display: inline-flex; align-items: center; min-height: 42px; }

  /* รอบ 98: การ์ดบนสุด (ร้านอาหารวันนี้ / KPI ที่ปัก) ใช้ระยะห่างของ .fit (gap) ไม่บวก margin ของตัวเองซ้ำ */
  .dash-fit > .rt-today, .dash-fit > .kpi-pinned { margin-bottom: 0; flex: none; }

  /* ---------- ตัวเลขสรุป ---------- */
  .dash-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; flex: none; }
  .dash-kpi {
    display: flex; align-items: center; gap: 14px; min-width: 0; padding: 14px 18px;
    background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  }
  .dash-kpi-ico {
    flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px;
    background: var(--brand-soft); color: var(--brand-strong, var(--brand));
  }
  .dash-kpi-ico.ok { background: var(--ok-soft); color: var(--ok); }
  .dash-kpi-body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
  .dash-kpi-label { color: var(--muted); font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-kpi-body > strong { font-size: 1.5rem; font-weight: 800; line-height: 1.25; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-kpi-sub { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: .8rem; white-space: nowrap; overflow: hidden; }
  .dash-kpi-sub > .muted { overflow: hidden; text-overflow: ellipsis; }
  .dash-delta { flex: none; padding: 0 8px; border-radius: 999px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .dash-delta.up { background: var(--ok-soft); color: var(--ok); }
  .dash-delta.down { background: var(--danger-soft); color: var(--danger); }
  .dash-mini-tag { flex: none; padding: 0 8px; border-radius: 999px; background: var(--danger-soft); color: var(--danger); font-weight: 600; }
  /* การ์ดแรก (ยอดขายวันนี้) เด่นด้วยสีร้าน */
  .dash-kpi.hl { background: var(--brand); color: var(--brand-ink); }
  .dash-kpi.hl .dash-kpi-ico { background: rgba(255,255,255,.2); color: var(--brand-ink); }
  .dash-kpi.hl .dash-kpi-label, .dash-kpi.hl .dash-kpi-sub > .muted { color: var(--brand-ink); opacity: .85; }

  /* ---------- กริดการ์ด ---------- */
  .dash-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
  .dash-daily { grid-area: daily; }
  .dash-hourly { grid-area: hourly; }
  .dash-tasks { grid-area: tasks; }
  .dash-pay { grid-area: pay; }
  .dash-top { grid-area: top; }
  .dash-low { grid-area: low; }
  .dash-grid { grid-template-areas: "tasks" "daily" "hourly" "pay" "top" "low"; }

  .panel.dash-card { margin: 0; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .dash-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; flex: none; }
  .dash-card-head h2 { margin: 0; font-size: 1.02rem; }
  .dash-card-meta { display: flex; flex-wrap: wrap; gap: 2px 14px; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
  .dash-card-meta .ok-text { font-weight: 600; }
  .dash-more { font-size: .84rem; font-weight: 600; color: var(--brand-strong, var(--brand)); text-decoration: none; white-space: nowrap; }
  .dash-more:hover { text-decoration: underline; }
  .dash-none { margin: 0; padding: 18px 8px; text-align: center; color: var(--muted); font-size: .9rem; }
  .dash-none.ok { color: var(--ok); }
  .dash-list { margin: 0; padding: 0; list-style: none; min-width: 0; }

  /* ---------- กราฟ ---------- */
  .dch { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
  .dch-plot { flex: 1 1 auto; position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr); min-height: 190px; padding-top: 20px; }
  .dch-y { position: relative; }
  .dch-y span {
    position: absolute; right: 8px; transform: translateY(50%);
    font-size: .7rem; line-height: 1; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
  }
  .dch-area { position: relative; min-width: 0; }
  .dch-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
  .dch-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
  .dch-base { stroke: var(--line); stroke-width: 1.5; }
  .dch-hit { fill: transparent; }
  .dch-bar { fill: var(--brand); fill-opacity: .36; transition: fill-opacity .12s; }
  .dch-bar.on { fill-opacity: 1; }
  .dch-slot:hover .dch-hit { fill: var(--brand-tint); }
  .dch-slot:hover .dch-bar { fill-opacity: .7; }
  .dch-slot:hover .dch-bar.on { fill-opacity: 1; }
  .dch-note {
    position: absolute; transform: translateX(-50%); margin-bottom: 3px; pointer-events: none;
    font-size: .72rem; font-weight: 700; line-height: 1.2; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
  }
  .dch-note.on { color: var(--brand-strong, var(--brand)); }
  .dch-note.end { transform: translateX(calc(-100% + 6px)); }
  .dch-x { display: flex; margin-left: 44px; height: 2.5em; flex: none; }
  .dch-xl { flex: 1 1 0; position: relative; min-width: 0; }
  .dch-xt {
    position: absolute; left: 50%; top: 5px; transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center; line-height: 1.15;
    font-size: .72rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
  }
  .dch-xt b { font-weight: 600; }
  .dch-xt small { font-size: .68rem; }
  .dch-xl.on .dch-xt { color: var(--brand-strong, var(--brand)); font-weight: 700; }
  .dch-xl.on .dch-xt b { font-weight: 800; }
  .dch-empty {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0; max-width: 90%;
    padding: 8px 14px; border-radius: 12px; background: var(--chip); color: var(--muted);
    font-size: .86rem; text-align: center; pointer-events: none;
  }
  /* เส้นรายชั่วโมง */
  .dch-line .dch-x { height: 1.9em; }
  .dch-x-abs { position: relative; display: block; }
  .dch-xa { position: absolute; top: 5px; transform: translateX(-50%); font-size: .7rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .dch-xa.on { color: var(--brand-strong, var(--brand)); font-weight: 700; }
  .dch-now { fill: var(--brand-tint); }
  .dch-tarea { fill: var(--brand); fill-opacity: .13; }
  .dch-tpath { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
  .dch-ypath { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; stroke-opacity: .75; }
  .dch-line .dch-hit:hover { fill: rgba(var(--brand-rgb), .08); }
  .dch-dot {
    position: absolute; width: 11px; height: 11px; border-radius: 50%; transform: translate(-50%, -50%);
    background: var(--brand); box-shadow: 0 0 0 3px var(--surface); pointer-events: none;
  }
  .dash-legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }
  .dash-key { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
  .dash-key::before { content: ""; width: 16px; height: 0; border-top: 3px solid var(--brand); border-radius: 2px; }
  .dash-key.yday::before { border-top: 2px dashed var(--muted); }

  /* ---------- งานที่รอ ---------- */
  .dash-task-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; flex: none; }
  .dash-tile {
    display: flex; flex-direction: column; min-width: 0; padding: 9px 12px; border-radius: 12px;
    background: var(--chip); color: var(--ink); text-decoration: none; line-height: 1.3;
    border: 1px solid transparent;
  }
  .dash-tile:hover { border-color: var(--line); }
  .dash-tile.on { background: var(--brand-tint); border-color: var(--brand-soft); }
  .dash-tile-label { font-size: .76rem; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-tile-val { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
  .dash-tile-val strong { flex: none; font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .dash-tile.on .dash-tile-val strong { color: var(--brand-strong, var(--brand)); }
  .dash-tile-sub { font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-tile-warn { min-width: 0; padding: 0 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn-text, #7a5300); font-size: .74rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-tile.shift-open { background: var(--ok-soft); }
  .dash-tile.shift-open .dash-tile-val strong { color: var(--ok); }
  .dash-tile.shift-none { background: var(--warn-soft); }
  .dash-tile.shift-none .dash-tile-label { color: var(--warn-text, #7a5300); }
  .dash-tile.shift-none .dash-tile-val strong { font-size: 1.05rem; line-height: 1.85rem; color: var(--warn-text, #7a5300); text-decoration: underline; text-underline-offset: 3px; }

  .dash-order {
    display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px;
    padding: 5px 6px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; border-radius: 8px;
  }
  .dash-order:first-child { border-top-color: transparent; }
  .dash-order:hover { background: var(--brand-tint); }
  .dash-order-main, .dash-order-amt { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
  .dash-order-main strong { font-size: .9rem; font-variant-numeric: tabular-nums; }
  .dash-order-main small, .dash-order-amt small { font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-order-amt { text-align: right; }
  .dash-order-amt strong { font-size: .9rem; }
  .dash-order .status-pill { font-size: .72rem; padding: 1px 8px; white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }

  /* ---------- ช่องทางชำระ ---------- */
  .dash-pays { display: flex; flex-direction: column; gap: 12px; }
  .dash-pay > .dash-pays { flex: 1 1 auto; justify-content: space-evenly; }
  .dash-pay-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 40px; align-items: baseline; gap: 4px 10px; }
  .dash-pay-name { font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-pay-amt { font-size: .9rem; font-weight: 700; }
  .dash-pay-pct { font-size: .8rem; color: var(--muted); text-align: right; }
  .dash-track { grid-column: 1 / -1; display: block; height: 8px; border-radius: 999px; background: var(--chip); overflow: hidden; }
  .dash-track.thin { height: 4px; }
  .dash-fill { display: block; height: 100%; border-radius: 999px; background: var(--brand); min-width: 3px; }
  .dash-channel { margin-top: auto; padding-top: 12px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 8px; flex: none; }
  .dash-channel-head { display: flex; justify-content: space-between; gap: 10px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
  .dash-channel-head span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-channel-head span::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--brand); }
  .dash-channel-head span + span::before { background: rgba(var(--brand-rgb), .28); }
  .dash-split { display: block; height: 10px; border-radius: 999px; background: rgba(var(--brand-rgb), .28); overflow: hidden; }
  .dash-split-a { display: block; height: 100%; background: var(--brand); border-right: 2px solid var(--surface); }

  /* ---------- สินค้าขายดี ---------- */
  .dash-tops { display: flex; flex-direction: column; }
  .dash-top-row {
    position: relative; display: grid; grid-template-columns: 26px minmax(0, 1fr) auto auto;
    align-items: center; gap: 10px; padding: 5px 0 8px;
  }
  .dash-rank {
    display: grid; place-items: center; width: 26px; height: 26px; border-radius: 9px;
    background: var(--chip); color: var(--muted); font-size: .8rem; font-weight: 800; font-variant-numeric: tabular-nums;
  }
  .dash-rank.hot { background: var(--brand-soft); color: var(--brand-strong, var(--brand)); }
  .dash-top-name { font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
  .dash-top-qty { font-size: .76rem; text-align: right; white-space: nowrap; }
  .dash-top-amt { font-size: .88rem; font-weight: 700; text-align: right; white-space: nowrap; min-width: 6.5em; }
  /* แถบสัดส่วนบาง ๆ ใต้แถว (แทนเส้นคั่น) */
  .dash-top-bar { position: absolute; left: 36px; right: 0; bottom: 2px; height: 3px; border-radius: 999px; background: var(--chip); overflow: hidden; }
  .dash-top-bar .dash-fill { opacity: .8; }

  /* ---------- สินค้าใกล้หมด ---------- */
  .dash-low-counts { display: flex; gap: 6px; flex-wrap: wrap; flex: none; margin-top: -4px; }
  .dash-count { padding: 1px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
  .dash-count.warn { background: var(--warn-soft); color: var(--warn-text, #7a5300); }
  .dash-count.danger { background: var(--danger-soft); color: var(--danger); }
  .dash-low-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line); }
  .dash-low-row:first-child { border-top: 0; }
  .dash-low-name { display: flex; align-items: baseline; gap: 8px; min-width: 0; line-height: 1.35; }
  .dash-low-name > span { min-width: 0; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-low-name small { flex: 0 1 auto; max-width: 45%; font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dash-low-qty { flex: none; display: inline-flex; align-items: baseline; gap: 4px; white-space: nowrap; }
  .dash-low-qty strong { font-size: .95rem; color: var(--warn-text, #9a6200); }
  .dash-low-qty small { font-size: .76rem; }
  .dash-low-row.out .dash-low-qty strong { color: var(--danger); }
  .dash-low-row.out .dash-low-name > span::before {
    content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; vertical-align: middle;
    border-radius: 50%; background: var(--danger);
  }
}

/* ---------- แท็บเล็ต ---------- */
@media screen and (min-width: 761px) and (max-width: 1024px) {
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "daily daily" "hourly tasks" "pay top" "low low"; }
  .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- จอคอม ---------- */
@media screen and (min-width: 1025px) {
  .dash-grid { grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); grid-template-areas: "daily tasks" "hourly pay" "top low"; }
  .dash-body { gap: 0; }
  /* รอบ 98: หน้าแรกไม่ใช่หน้า "พอดีจอ" — ทั้งหน้า (.content) เลื่อน การ์ดไม่ถูกตัด */
  .content > .fit.dash-fit { flex: none; }
  .dash-fit > .fit-body.scroll.dash-body { flex: none; min-height: 0; overflow: visible; margin: 0; padding: 0; }
}
@media screen and (min-width: 1025px) and (max-width: 1360px) {
  .dash-kpi { padding: 12px 14px; gap: 12px; }
  .dash-kpi-ico { width: 38px; height: 38px; border-radius: 12px; }
  .dash-kpi-body > strong { font-size: 1.3rem; }
  .dash-seg button small { max-width: 90px; }
  .dash-kpi-sub { flex-wrap: wrap; white-space: normal; row-gap: 0; }
  .dash-kpi-sub > .muted { white-space: normal; }
}
/* จอใหญ่: 3 คอลัมน์ ทั้งหน้าพอดีจอ */
@media screen and (min-width: 1500px) {
  .dash-grid {
    grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "daily tasks top" "hourly pay low";
  }
}
/* ---------- มือถือ ---------- */
@media screen and (max-width: 760px) {
  .dash-tools { flex-wrap: wrap; }
  .dash-tools .dash-scope { flex: 1 1 100%; }
  .dash-scope button { flex: 1 1 0; }
  .dash-tools .dash-days { flex: 1 1 auto; }
  .dash-days button { flex: 1 1 0; padding: 4px 6px; }
  .dash-rep-btn { display: none !important; }
  .dash-pos-btn { padding-left: 12px; padding-right: 12px; }
  .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .dash-kpi { padding: 12px 14px; align-items: flex-start; }
  .dash-kpi-ico { display: none; }
  .dash-kpi-body > strong { font-size: 1.15rem; }
  .dash-kpi-sub { flex-wrap: wrap; white-space: normal; row-gap: 2px; font-size: .76rem; }
  .dash-kpi-sub > .muted { white-space: normal; }
  .dash-grid { gap: 12px; }
  .panel.dash-card { padding: 14px; }
  .dch-plot { min-height: 170px; grid-template-columns: 38px minmax(0, 1fr); }
  .dch-x { margin-left: 38px; }
  .dch-xt small { display: none; }
  .dch-x { height: 1.9em; }
  .dash-order .status-pill { max-width: 110px; }
  .dch-xa.minor:not(.on) { display: none; }
}
