/* Templates (قالب‌ها) — a Hambord panel built from studio widgets. prefix hbp- */
.hbp { position: relative; display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 760px; border: 1px solid var(--border); border-radius: 16px; background: var(--background); overflow: clip; }
.hbp-side { display: flex; flex-direction: column; gap: 14px; padding: 16px 12px; border-inline-end: 1px solid var(--border); background: var(--card); position: sticky; top: 0; align-self: start; min-height: 760px; }
.hbp-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 12px; border-bottom: 1px solid var(--border); }
.hbp-brand b { display: block; font-size: 14px; }
.hbp-brand small, .hbp-me small { display: block; color: var(--muted-foreground); font-size: 11.5px; }
.hbp-logo { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--primary); color: var(--primary-foreground, #fff); }
.hbp-pages { display: flex; flex-direction: column; gap: 2px; }
.hbp-pg { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--foreground); font: inherit; font-size: 13.5px; cursor: pointer; text-align: start; }
.hbp-pg:hover { background: var(--muted); }
.hbp-pg[aria-current="page"] { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }
.hbp-pg .i { width: 16px; height: 16px; }
.hbp-me { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px 6px 0; border-top: 1px solid var(--border); }
.hbp-me b { font-size: 13px; }
.hbp-av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--secondary); font-weight: 700; }
.hbp-main { min-width: 0; padding: 16px 18px 24px; display: flex; flex-direction: column; gap: 14px; }
.hbp-top { display: flex; align-items: center; min-height: 36px; }
.hbp-h { margin: 0; font-size: 22px; }
.hbp-tools { display: flex; gap: 8px; flex-wrap: wrap; }
/* studio bar above the panel: the panel's actions live outside the panel */
.hbp-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.hbp-bar a { font-size: 12.5px; text-decoration: none; }
.hbp-bar h1 { margin: 2px 0 0; font-size: 22px; }
.hbp-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; align-items: stretch; }
.hbp-cell { grid-column: span var(--w); min-width: 0; }
/* chart cells: the chart widget's own card (.w.kx-chart) is the frame */
.hbp-cell.is-chart { min-width: 0; min-height: 300px; display: flex; container: hbpcell / inline-size; }
.hbp-cell.is-chart > .w { flex: 1; min-width: 0; }
.hbp-cell.is-chart .kx-chart .w-title { min-width: 0; }
.hbp-cell.is-chart .kx-chart .w-title > span { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* KPI cards — the kpi widget's card (.kx-card); the template fixes the column count per block */
.hbp-kpis.kx-grid { grid-template-columns: repeat(var(--n), minmax(0, 1fr)); height: 100%; }
.hbp-kpis .kx-card { grid-column: auto; }
.hbp-cell[style*="--w:4"] .hbp-kpis, .hbp-cell[style*="--w:3"] .hbp-kpis { grid-template-columns: 1fr; }
/* the live widget: only its stage, the player chrome is hidden */
.hbp-cell.is-widget .demo-top, .hbp-cell.is-widget .transport, .hbp-cell.is-widget .stepcard, .hbp-cell.is-widget .storyboard, .hbp-cell.is-widget .mode-desc { display: none !important; }
.hbp-cell.is-widget .demo-shell { gap: 0; }
.hbp-cell.is-widget .stage-box { border-radius: 14px; }
.hbp-cell.is-widget.is-interactive .stage-box, .hbp-cell.is-widget .is-interactive .stage-box { outline: none; box-shadow: none; }
/* tour cursor */
.hbp-cur { position: absolute; top: 0; left: 0; width: 22px; height: 22px; z-index: 60; pointer-events: none; opacity: 0; transition: opacity .25s; }
.hbp-cur.on { opacity: 1; }
.hbp-cur svg { width: 22px; height: 22px; transition: transform .15s; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.hbp-cur.press svg { transform: scale(.82); }
/* gallery */
.hbp-gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.hbp-gc { display: grid; gap: 8px; padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: var(--card); color: var(--foreground); text-decoration: none; }
.hbp-gc:hover { border-color: var(--primary); }
.hbp-gc b { font-size: 16px; }
.hbp-gc .muted { font-size: 13px; line-height: 1.8; }
.hbp-gp { display: flex; flex-wrap: wrap; gap: 4px; }
/* export dialog */
.hbp-dlgback { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; }
.hbp-dlg { width: min(520px, 100%); background: var(--popover); color: var(--foreground); border: 1px solid var(--border); border-radius: 16px; padding: 18px; display: grid; gap: 10px; box-shadow: var(--shadow-pop); }
.hbp-dlg h4 { margin: 0; }
.hbp-dlg p { margin: 0; font-size: 13px; }
.hbp-dlg .foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
@media (max-width: 900px) {
  .hbp { grid-template-columns: 1fr; }
  .hbp-side { position: static; min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; border-inline-end: 0; border-bottom: 1px solid var(--border); }
  .hbp-pages { flex-direction: row; overflow-x: auto; flex: 1 1 100%; }
  .hbp-pg { width: auto; white-space: nowrap; }
  .hbp-me { display: none; }
  .hbp-cell { grid-column: span 12; }
}
@media (max-width: 560px) {
  .hbp-kpis.kx-grid { grid-template-columns: 1fr; }
  .hbp-main { padding: 12px; }
}

/* frame: desktop proportions (16:10), never taller than the studio window; the page scrolls INSIDE the panel */
.hbp { --hbp-off: 210px; aspect-ratio: 16 / 10; width: min(100%, calc((100vh - var(--hbp-off)) * 1.6)); min-height: 0; margin-inline: auto; grid-template-rows: minmax(0, 1fr); }
.hbp-side { position: static; min-height: 0; height: 100%; overflow: auto; }
.hbp-main { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 900px) { .hbp { aspect-ratio: auto; width: 100%; grid-template-rows: none; } .hbp-side { height: auto; } .hbp-main { overflow-y: visible; } }

/* page-level dialogs: a widget's dialog covers the whole panel, not just the widget */
.hbp-over { position: absolute; inset: 0; z-index: 80; pointer-events: none; border-radius: inherit; overflow: hidden; }
.hbp-over.on { pointer-events: auto; background: rgb(0 0 0 / .42); backdrop-filter: blur(2px); }
.hbp-over .dlg { pointer-events: auto; }
.hbp .dlg-back, .dsn-panel .dlg-back { display: none; }

/* chart cards (SparkCard) row on dashboards */
.hbp .spc-grid { grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr)); }
.hbp-cell.is-spark { min-width: 0; }
@media (max-width: 900px) { .hbp .spc-grid { grid-template-columns: 1fr; } }

/* small pie / donut / radial cells (under ~420px): the tag legend goes BELOW the chart, centred */
@container hbpcell (max-width: 420px) {
  .hbp-cell.is-ring .hb-pie-in, .hbp-cell.is-ring .hb-rad-in { flex-direction: column; align-items: stretch; }
  .hbp-cell.is-ring .hb-pie-l, .hbp-cell.is-ring .hb-rad-l { order: 0; justify-content: center; align-content: start; }
}
/* narrow chart cells: title on its own row, action buttons under it on the left (same as the combo/mobile card) */
@container hbpcell (max-width: 560px) {
  .hbp-cell .kx-chart { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  .hbp-cell .kx-chart .w-actions { grid-column: 1; grid-row: 2; padding: 0 12px 8px 12px; justify-content: flex-end; }
  .hbp-cell .kx-chart .w-body { grid-row: 3; }
}
@container hbpcell (max-width: 420px) {
  .hbp-cell.is-ring .hb-pie-l, .hbp-cell.is-ring .hb-rad-l { align-self: center; margin-inline: auto; }
}

/* pie / donut / radial cells in templates: taller cards; the three actions stay on ONE row above the chart (never over it);
   the plot grows so every legend tag is visible; neighbours in the same row stretch to the same height (grid stretch) */
.hbp-cell.is-chart { min-height: 440px; }
.hbp-cell.is-chart .kx-chart .w-actions { flex-wrap: nowrap; }
.hbp-cell.is-ring .kx-chart .w-body { overflow: visible; }
.hbp-cell.is-ring .kx-plot { overflow: visible; min-height: 0; flex: 1 0 auto; }
.hbp-cell.is-ring .hb-pie-c, .hbp-cell.is-ring .hb-rad-c { min-height: 180px; }
.hbp-cell.is-ring .hb-pie-l .badge, .hbp-cell.is-ring .hb-rad-l .badge { max-width: none; }
@container hbpcell (max-width: 560px) {
  .hbp-cell .kx-chart .w-actions { gap: 4px; padding-bottom: 10px; }
  .hbp-cell .kx-chart .w-actions .btn.sm { height: 28px; padding-inline: 7px; gap: 4px; font-size: 11.5px; }
  .hbp-cell .kx-chart .w-actions .btn.sm .i { width: 13px; height: 13px; }
}
