/* «نمایش عدد» (kpi.js) and «نمودار» (chartx.js) — own prefix kx- */

/* ── نمایش عدد: metric cards, same look as .hbp-kpi (templates.css) ── */
.kx-kpi .w-body { overflow-y: auto; overflow-x: hidden; }
.kx-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; align-content: start; min-width: 0; }
.kx-card { grid-column: span 2; border: 1px solid var(--border); border-radius: 14px; background: var(--card); padding: 16px 18px; display: grid; gap: 6px; align-content: start; min-width: 0; }
.kx-lb { display: flex; align-items: center; gap: 8px; min-width: 0; }
.kx-ic { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; flex: none; background: color-mix(in srgb, var(--primary) 10%, var(--card)); color: var(--primary); }
.kx-ic .i { width: 15px; height: 15px; }
.kx-lb small { font-size: 13px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kx-card b { font-family: Morabba, inherit; font-size: 30px; font-weight: 600; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kx-card b span { font-size: 13px; font-weight: 400; color: var(--muted-foreground); margin-inline-start: 4px; font-family: "Vazirmatn Variable", sans-serif; }
.kx-ks { font-size: 12.5px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kx-ks em { font-style: normal; font-weight: 600; }
.kx-ks em.up { color: var(--success-ink, #15803d); }
.kx-ks em.down { color: var(--destructive); }
.kx-sk { gap: 10px; }
.kx-err { grid-column: 1 / -1; display: grid; gap: 6px; justify-items: start; padding: 16px 18px; border: 1px solid color-mix(in srgb, var(--destructive) 35%, var(--border)); border-radius: 14px; background: color-mix(in srgb, var(--destructive) 6%, var(--card)); }
.kx-err b { font-size: 15px; color: var(--destructive); }
.kx-err span { font-size: 13px; color: var(--muted-foreground); }
.kx-err .btn { margin-top: 4px; }
[data-dev="tablet"] .kx-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
[data-dev="tablet"] .kx-card { grid-column: span 1; }
[data-dev="mobile"] .kx-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
[data-dev="mobile"] .kx-card { grid-column: span 1; padding: 12px 14px; }
[data-dev="mobile"] .kx-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
[data-dev="mobile"] .kx-card b { font-size: 24px; }

/* ── نمودار: frame, caption, plot and the table under it ── */
.kx-chart .w-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 12px 12px 0 12px; max-width: 100%; }
.kx-chart .w-actions .btn { white-space: nowrap; }
.kx-chart .w-body { gap: 8px; }
.kx-cap { flex: none; font-size: 12.5px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kx-plot { flex: 1 1 0; min-height: 200px; min-width: 0; position: relative; overflow: hidden; }
.kx-tblwrap { flex: none; height: 300px; min-height: 0; display: flex; }
.kx-tblwrap[hidden] { display: none; }
.kx-tblwrap > div { flex: 1; min-width: 0; height: 100%; }
.kx-tblwrap .w { height: 100%; }
[data-dev="mobile"] .kx-plot { min-height: 220px; }
[data-dev="mobile"] .kx-tblwrap { height: 340px; }
[data-dev="mobile"] .kx-chart { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
[data-dev="mobile"] .kx-chart .w-actions { grid-column: 1; grid-row: 2; padding: 0 12px 8px 12px; }
[data-dev="mobile"] .kx-chart .w-body { grid-row: 3; }

/* empty state */
.kx-empty { height: 100%; display: grid; place-content: center; justify-items: center; gap: 4px; text-align: center; color: var(--muted-foreground); font-size: 12.5px; }
.kx-empty b { color: var(--foreground); font-size: 14px; font-weight: 600; }

/* custom plot kinds */
.kx-cw { position: absolute; inset: 0; }
.kx-c { position: absolute; inset: 14px 50px 30px 14px; }
.kx-c-hm { inset: 6px 6px 6px 6px; }
.kx-cols { position: absolute; inset: 0; display: flex; gap: 14px; align-items: stretch; }
.kx-hist { gap: 4px; }
.kx-col { flex: 1; min-width: 0; height: 100%; position: relative; display: flex; align-items: flex-end; justify-content: center; }
.kx-stk { width: min(46px, 72%); display: flex; flex-direction: column-reverse; border-radius: 6px 6px 0 0; overflow: hidden; }
.kx-stk i { display: grid; place-items: center; font-style: normal; min-height: 0; }
.kx-stk em { font-style: normal; font-size: 10.5px; color: var(--card); }
.kx-col:hover .kx-stk { opacity: .88; }
.kx-bar { position: relative; width: min(40px, 80%); border-radius: 5px 5px 0 0; min-height: 0; }
.kx-bar em { position: absolute; bottom: 100%; left: 50%; translate: -50% 0; font-style: normal; font-size: 10.5px; white-space: nowrap; padding-bottom: 2px; }
.kx-col:hover .kx-bar { opacity: .85; }
.kx-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.kx-hits { position: absolute; inset: 0; }
.kx-hits i { position: absolute; top: 0; bottom: 0; border-radius: 6px; }
.kx-hits i:hover { background: color-mix(in srgb, var(--foreground) 6%, transparent); }
.kx-pt { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--card); border: 2.5px solid var(--chart-1); translate: 50% 50%; pointer-events: none; }
.kx-dot { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--chart-1); opacity: .85; translate: 50% 50%; }
.kx-dot:hover { opacity: 1; box-shadow: 0 0 0 4px color-mix(in srgb, var(--chart-1) 22%, transparent); }
.kx-dot em { position: absolute; right: 14px; bottom: -5px; font-style: normal; font-size: 10.5px; white-space: nowrap; }
.kx-ax { position: absolute; top: 14px; bottom: 30px; right: 0; width: 46px; }
.kx-ax span { position: absolute; right: 4px; translate: 0 50%; font-size: 11px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kx-xrow { position: absolute; left: 14px; right: 50px; bottom: 6px; display: flex; gap: 14px; }
.kx-xrow span { flex: 1; min-width: 0; text-align: center; font-size: 11px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kx-xrow2 { justify-content: space-between; }
.kx-xrow2 span { flex: none; }
.kx-hm { display: grid; gap: 5px; height: 100%; direction: rtl; }
.kx-hh, .kx-hd { font-size: 11px; color: var(--muted-foreground); display: flex; align-items: center; justify-content: center; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kx-hd { justify-content: flex-start; }
.kx-cell { border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-style: normal; min-height: 0; min-width: 0; }
.kx-cell:hover { outline: 2px solid var(--foreground); outline-offset: -2px; }

/* hover tooltip for the custom kinds (look of .hb-tt from HBCharts) */
.kx-tip { position: absolute; z-index: 4; pointer-events: none; width: max-content; max-width: 240px; }
.kx-tip[hidden] { display: none; }

/* ── «ویرایش» dialog ── */
.kx-dlg { width: 400px; max-width: calc(100% - 24px); }
.kx-types { display: flex; flex-wrap: wrap; gap: 6px; }
.kx-type { height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--background); color: var(--foreground); font: inherit; font-size: 13px; cursor: pointer; }
.kx-type:hover { background: var(--muted); }
.kx-type[aria-pressed="true"] { background: color-mix(in srgb, var(--primary) 12%, var(--card)); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.kx-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kx-range label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted-foreground); min-width: 0; }
.kx-range select { height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--background); color: var(--foreground); padding: 0 8px; font: inherit; font-size: 13px; min-width: 0; width: 100%; }
.kx-swrow { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.kx-sw { width: 38px; height: 22px; border-radius: 99px; border: 0; background: var(--muted); position: relative; cursor: pointer; padding: 0; flex: none; transition: background .2s; }
.kx-sw i { position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); transition: inset-inline-start .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.kx-sw.on { background: var(--primary); }
.kx-sw.on i { inset-inline-start: 19px; }
.kx-dlg-tools { margin-top: 2px; }
.kx-dlg .foot .btn { white-space: nowrap; }
[data-dev="mobile"] .kx-dlg { width: calc(100% - 24px); }
.kx-menu { width: 200px; }

/* ── «نمودار»: toggles, reasons, pending kinds, combo ── */
.kx-tog { flex: none; display: flex; flex-wrap: wrap; gap: 6px; }
.kx-tog[hidden] { display: none; }
.kx-chip { height: 28px; padding: 0 10px; border-radius: 99px; border: 1px dashed var(--border); background: var(--card); color: var(--foreground); font: inherit; font-size: 12.5px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.kx-chip small { color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.kx-chip.on { border-style: solid; border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--card)); font-weight: 600; }
.kx-why { font-size: 12.5px; color: var(--muted-foreground); line-height: 1.6; margin-top: 6px; min-width: 0; }
.kx-pend { padding: 12px; }
.kx-pend b { font-size: 13.5px; }
.kx-tgl { display: grid; gap: 8px; }
.kx-bev { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted-foreground); }
.kx-bev input { height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--background); color: var(--foreground); padding: 0 10px; font: inherit; font-size: 13px; width: 100%; min-width: 0; }
.kx-mini { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted-foreground); }
.kx-mini select { height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--background); color: var(--foreground); padding: 0 6px; font: inherit; font-size: 12.5px; }
.kx-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: stretch; min-width: 0; }
.kx-pair > div { display: flex; min-width: 0; min-height: 460px; }
.kx-pair > div > .w { flex: 1; min-width: 0; }
/* the two cards are half width: title, then the action row, then the chart (same stacking as mobile) */
.kx-pair .kx-chart { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
.kx-pair .kx-chart .w-actions { grid-column: 1; grid-row: 2; padding: 0 12px 8px 12px; }
.kx-pair .kx-chart .w-body { grid-row: 3; }
.kx-pair .kx-plot { min-height: 240px; }
.kx-pair .kx-combined { grid-column: 1 / -1; }
.kx-pair .kx-combined[hidden] { display: none; }
.kx-chart .w-actions .btn:disabled { opacity: .5; cursor: not-allowed; }
.kx-chip:disabled { opacity: .5; cursor: not-allowed; }
.kx-val { margin-inline-start: auto; font-size: 12.5px; font-weight: 400; color: var(--muted-foreground); white-space: nowrap; font-variant-numeric: tabular-nums; }
.kx-range[hidden], .kx-bev[hidden] { display: none; }
.kx-card2 { border: 1px solid var(--border); border-radius: 14px; background: var(--card); padding: 12px 14px; display: grid; gap: 8px; min-width: 0; }
.kx-card2[hidden] { display: none; }
.kx-card2 > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.kx-card2 > header b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kx-card2 > header small { font-size: 12px; color: var(--muted-foreground); white-space: nowrap; }
.kx-plot-s { flex: none; height: 210px; min-height: 0; overflow: hidden; }
.kx-combined .kx-plot-s { height: 240px; }
[data-dev="mobile"] .kx-plot-s { height: 220px; }
[data-dev="mobile"] .kx-combined .kx-plot-s { height: 240px; }
[data-dev="mobile"] .kx-pair { grid-template-columns: minmax(0, 1fr); }
[data-dev="mobile"] .kx-pair > div { min-height: 420px; }

/* ── «کارت نمودار» (sparkcard.js): display-only cards, RTL grid 3 / 2 / 1 ── */
.spc .w-body { overflow-y: auto; overflow-x: hidden; }
.spc-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-content: start; min-width: 0; }
.spc-card { border: 1px solid var(--border); border-radius: 14px; background: var(--card); padding: 14px 16px; display: grid; gap: 4px; align-content: start; min-width: 0; }
.spc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.spc-lb { font-size: 13px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spc-dl { flex: none; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.spc-dl.good { color: var(--success-ink, #15803d); background: color-mix(in srgb, #16a34a 12%, var(--card)); }
.spc-dl.bad { color: var(--destructive); background: color-mix(in srgb, var(--destructive) 12%, var(--card)); }
.spc-val { font-family: Morabba, inherit; font-size: 26px; font-weight: 600; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spc-val small { font-family: "Vazirmatn Variable", sans-serif; font-size: 12.5px; font-weight: 400; color: var(--muted-foreground); margin-inline-start: 4px; }
.spc-note { font-size: 12px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spc-spark { position: relative; height: 56px; margin-top: 6px; min-width: 0; padding: 0 8px; box-sizing: border-box; }
.spc-pl { position: absolute; inset: 4px 8px; }
.spc-spark svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.spc-dot { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--card); border: 2.5px solid var(--chart-1); translate: -50% -50%; }
.spc-bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 4px; direction: rtl; }
.spc-bars i { flex: 1; min-width: 0; border-radius: 4px 4px 0 0; background: color-mix(in srgb, var(--chart-1) 35%, var(--card)); }
.spc-bars i.on { background: var(--chart-1); }
[data-dev="tablet"] .spc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
[data-dev="mobile"] .spc-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
[data-dev="mobile"] .spc-card { padding: 12px 14px; }
[data-dev="mobile"] .spc-val { font-size: 22px; }
/* combo / mobile: the action row sits on the left, like the full-width card */
.kx-pair .kx-chart .w-actions, [data-dev="mobile"] .kx-chart .w-actions { justify-content: flex-end; }
/* combine popover: real buttons only */
.kx-menu .mi { justify-content: center; border: 1px solid var(--border); background: var(--secondary); }
.kx-menu .mi:hover { border-color: var(--primary); }
/* «کارت عدد» and «کارت نمودار» widgets show ONE card, centred */
.kx-grid.kx-one, .spc-grid.spc-one, [data-dev] .kx-grid.kx-one, [data-dev] .spc-grid.spc-one { grid-template-columns: minmax(0, 340px); justify-content: center; }
.spc-bars i { background: color-mix(in srgb, var(--spc, var(--chart-1)) 35%, var(--card)); }
.spc-bars i.on { background: var(--spc, var(--chart-1)); }
.spc-empty .spc-pl { border-bottom: 2px dashed var(--border); inset: auto 8px 50% 8px; }
