/* Dashboards and the report builder (screens-dashboards.jsx). Mobile-first; desktop through the qapp container. */

/* header: dashboard switcher in the title */
.db-switch { display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 0; cursor: pointer; color: var(--text); text-align: left; min-width: 0; max-width: 100%; }
.db-switch .h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-switch .chev { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); }
.db-switch:hover .chev { background: var(--surface-3); color: var(--text); }
.db-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: var(--fs-s); color: var(--text-2); }
.db-meta .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--line-strong); }

/* global filter bar */
.db-bar { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.db-bar .periods { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--s-4)); padding: 0 var(--s-4) 2px; }
.db-bar .periods::-webkit-scrollbar { display: none; }
.db-bar .periods .chip { flex: none; }
.db-bar .line2 { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.db-bar .owner { flex: 1 1 auto; min-width: 0; }
.db-pick { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px 0 6px; border-radius: var(--r-2); border: 1px solid var(--line-strong); background: var(--surface); font-size: var(--fs-s); font-weight: 560; color: var(--text); cursor: pointer; min-width: 0; max-width: 100%; }
.db-pick .ellip { flex: 1 1 auto; }
.db-fresh { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.db-fresh .live { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* widget grid: phone — two columns, KPIs side by side, everything else full width, in layout order */
.db-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); grid-auto-flow: row dense; }
.db-grid > .dw { grid-column: span 2; }
.db-grid > .dw.half { grid-column: span 1; }
.dw { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-3); box-shadow: var(--shadow-1); min-width: 0; display: flex; flex-direction: column; position: relative; }
.dw-h { display: flex; align-items: flex-start; gap: var(--s-2); padding: var(--s-3) var(--s-3) 0 var(--s-4); min-height: 44px; }
.dw-h .tt { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 auto; padding-top: 6px; }
.dw-h .tt b { font-size: var(--fs-m); font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.dw-h .tt span { font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dw-b { container-type: inline-size; container-name: dwb; padding: var(--s-3) var(--s-4) var(--s-4); flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--s-3); }
.dw-menu { flex: none; color: var(--muted); }

/* KPI tile (in view the whole tile opens the widget menu) */
.dk-btn { display: block; width: 100%; border: 0; padding: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: var(--r-3); }
.dk-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dk { padding: var(--s-4); display: flex; flex-direction: column; gap: 6px; min-height: 132px; }
.dk .lab { display: flex; align-items: center; gap: 6px; font-size: var(--fs-s); color: var(--text-2); font-weight: 540; min-width: 0; }
.dk .lab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dk .val { font-size: var(--fs-xl); font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
.dk .delta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: var(--fs-xs); color: var(--muted); }
.dk .spark { margin-top: auto; height: 28px; }
.dlt { display: inline-flex; align-items: center; gap: 2px; height: 20px; padding: 0 6px; border-radius: 5px; font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dlt.up { background: var(--ok-soft); color: var(--ok); }
.dlt.down { background: var(--danger-soft); color: var(--danger); }
.dlt.flat { background: var(--surface-2); color: var(--text-2); }

/* charts */
.ch { position: relative; width: 100%; min-width: 0; }
.ch svg { display: block; overflow: visible; }
.ch.fill { flex: 1 1 auto; }
.ch.fill svg { position: absolute; left: 0; top: 0; }
.ch .grid line { stroke: var(--line); stroke-width: 1; }
.ch .grid line.base { stroke: var(--line-strong); }
.ch text { fill: var(--muted); font-size: 11px; font-family: var(--font-ui); font-variant-numeric: tabular-nums; }
.ch .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch .ln.prev { stroke-dasharray: 4 4; stroke-width: 1.5; opacity: 0.7; }
.ch .mk { stroke: var(--surface); stroke-width: 2; }
.ch .cross { stroke: var(--line-strong); stroke-width: 1; }
.ch-tip { position: absolute; z-index: 3; pointer-events: none; min-width: 140px; max-width: 240px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); box-shadow: var(--shadow-2); padding: 8px 10px; font-size: var(--fs-xs); display: flex; flex-direction: column; gap: 4px; }
.ch-tip b { font-size: var(--fs-xs); color: var(--text); }
.ch-tip .r { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.ch-tip .r i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.ch-tip .r span:last-child { margin-left: auto; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; padding-left: 8px; }
.ch-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-xs); color: var(--text-2); }
.ch-legend span { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.ch-legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.ch-legend i.dash { height: 0; border-top: 2px dashed var(--muted); border-radius: 0; width: 14px; }

/* horizontal bars (categories) */
.hb { display: flex; flex-direction: column; gap: 10px; }
.hb-r { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hb-r .top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); font-size: var(--fs-s); min-width: 0; }
.hb-r .top .k { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.hb-r .top .k span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-r .top .v { font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.hb-r .trk { height: 8px; border-radius: 4px; background: var(--surface-2); display: flex; gap: 2px; overflow: hidden; }
.hb-r .trk i { display: block; height: 100%; border-radius: 0; }
.hb-r .trk i:last-of-type { border-radius: 0 4px 4px 0; }

/* donut */
.dn { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); }
.dn .ring { position: relative; flex: none; }
.dn .ring .mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; }
.dn .ring .mid b { font-size: var(--fs-l); font-weight: 680; font-variant-numeric: tabular-nums; }
.dn .ring .mid span { font-size: var(--fs-xs); color: var(--muted); }
.dn .ring path { stroke: var(--surface); stroke-width: 2; }
.dn-l { display: flex; flex-direction: column; gap: 6px; width: 100%; min-width: 0; }
.dn-l .r { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 40px; gap: 8px; align-items: center; font-size: var(--fs-s); }
.dn-l .r i { width: 10px; height: 10px; border-radius: 3px; }
.dn-l .r span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dn-l .r .v { font-variant-numeric: tabular-nums; color: var(--text-2); text-align: right; white-space: nowrap; }
.dn-l .r .p { font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; font-size: var(--fs-xs); }

/* funnel */
.fn { display: flex; flex-direction: column; gap: 2px; }
.fn-r { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; padding: 3px 0; }
.fn-r .top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); font-size: var(--fs-s); }
.fn-r .top .k { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.fn-r .top .k span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fn-r .top .v { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-2); }
.fn-r .top .v b { color: var(--text); font-weight: 650; }
.fn-r .shape { height: 18px; display: flex; justify-content: center; }
.fn-r .shape i { display: block; height: 100%; border-radius: 4px; min-width: 6px; }
.fn-step { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* goal (plan / fact) */
.gl { display: flex; flex-direction: column; gap: var(--s-3); }
.gl .big { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.gl .big b { font-size: var(--fs-2xl); font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.gl .big span { font-size: var(--fs-s); color: var(--text-2); font-variant-numeric: tabular-nums; }
.gl .trk { position: relative; height: 14px; border-radius: 7px; background: var(--surface-2); }
.gl .trk > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 7px; background: var(--accent); }
.gl .trk > i.over { background: var(--ok); }
.gl .pace { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--text); border-radius: 1px; }
.gl .pace::after { content: ""; position: absolute; top: -3px; left: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--text); }
.gl .axis { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.gl .kv3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-2); }
.gl .kv3 > div { display: flex; flex-direction: column; gap: 2px; padding: var(--s-2) var(--s-3); border-radius: var(--r-2); background: var(--surface-2); min-width: 0; }
.gl .kv3 span { font-size: var(--fs-xs); color: var(--muted); }
.gl .kv3 b { font-size: var(--fs-s); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* leaderboard */
.lb { display: flex; flex-direction: column; }
.lb-r { display: grid; grid-template-columns: 24px 32px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lb-r:last-child { border-bottom: 0; }
.lb-r .rk { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--text-2); background: var(--surface-2); font-variant-numeric: tabular-nums; }
.lb-r .rk.g1 { background: color-mix(in oklch, var(--warn) 22%, var(--surface)); color: var(--warn); }
.lb-r .rk.g2 { background: var(--surface-3); color: var(--text); }
.lb-r .rk.g3 { background: color-mix(in oklch, var(--platform) 18%, var(--surface)); color: var(--platform); }
.lb-r .nm { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.lb-r .nm b { font-size: var(--fs-s); font-weight: 580; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-r .v { text-align: right; display: flex; flex-direction: column; gap: 1px; font-variant-numeric: tabular-nums; }
.lb-r .v b { font-size: var(--fs-s); }
.lb-r .v span { font-size: var(--fs-xs); color: var(--muted); }

/* table widget: phone list */
.dt-list { display: flex; flex-direction: column; }
.dt-li { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.dt-li:last-child { border-bottom: 0; }
.dt-li .r1 { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--fs-s); font-weight: 580; }
.dt-li .r1 .num { white-space: nowrap; flex: none; }
.dt-li .r1 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dt-li .r2 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: var(--fs-xs); color: var(--muted); }
.dw .tablewrap { border: 0; border-radius: 0; margin: 0 calc(-1 * var(--s-4)) calc(-1 * var(--s-4)); }
.dw .t th:first-child, .dw .t td:first-child { padding-left: var(--s-4); }
.dw .t th:last-child, .dw .t td:last-child { padding-right: var(--s-4); }

/* widget states */
.dw-state { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: var(--s-4) var(--s-2); color: var(--text-2); font-size: var(--fs-s); min-height: 120px; }
.dw-state .g { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.dw-state.err .g { background: var(--danger-soft); color: var(--danger); }
.dw-state.warn .g { background: var(--warn-soft); color: var(--warn); }
.dw-note { font-size: var(--fs-xs); color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* edit mode */
.db-editbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4); border-radius: var(--r-3); background: var(--accent-soft); border: 1px solid var(--accent-line); font-size: var(--fs-s); }
.db-editbar .grow { min-width: 160px; }
.dw.editing { border-style: dashed; border-color: var(--accent-line); box-shadow: none; }
.dw.editing .dw-h { cursor: grab; }
.dw-grip { color: var(--muted); flex: none; margin-top: 6px; }
.dw-tools { display: flex; gap: 2px; flex: none; }
.dw-move { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-3) var(--s-3); flex-wrap: wrap; }
.dw-move .seg { flex: 0 0 auto; }
.dw-resize { display: none; }
.dw.dragging { opacity: 0.35; }
.dw.dragging .dw-h { cursor: grabbing; }
.dw-ghost { position: relative; z-index: 2; border: 2px dashed var(--accent); backdrop-filter: blur(2px); border-radius: var(--r-3); background: color-mix(in oklch, var(--accent) 8%, transparent); }
.dw-add { border: 1.5px dashed var(--line-strong); border-radius: var(--r-3); background: transparent; min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--text-2); font-size: var(--fs-s); font-weight: 560; cursor: pointer; grid-column: span 2; }
.dw-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* widget kind tiles */
.kinds { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.kind { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r-2); border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; text-align: left; min-height: 56px; min-width: 0; }
.kind .ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.kind b { font-size: var(--fs-s); font-weight: 600; display: block; }
.kind span { font-size: var(--fs-xs); color: var(--muted); display: block; line-height: 1.3; }
.kind.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.kind.on .ic { background: var(--accent); color: var(--accent-ink); }

/* builder */
.rb { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-4); }
.rb-side { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
.rb-sec { display: flex; flex-direction: column; gap: var(--s-3); }
.rb-sec > .eyebrow { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.rb-pill { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 6px 6px 12px; border-radius: var(--r-2); border: 1px solid var(--line-strong); background: var(--surface); font-size: var(--fs-s); min-width: 0; }
.rb-pill .grow { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rb-pill .grow b { font-weight: 580; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-pill .grow span { font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-pill .ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.rb-add { display: inline-flex; align-items: center; gap: 6px; border: 1px dashed var(--line-strong); background: transparent; border-radius: var(--r-2); min-height: 40px; padding: 0 12px; font-size: var(--fs-s); font-weight: 560; color: var(--text-2); cursor: pointer; }
.rb-add:hover { border-color: var(--accent); color: var(--accent); }
.rb-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s-2); }
.rb-prev { position: relative; }
.rb-prev .dw { min-height: 300px; }
.rb-side .seg { display: flex; flex-wrap: wrap; overflow: visible; }
.rb-src { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }

/* templates gallery */
.tpl { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-4); border-radius: var(--r-3); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-1); min-width: 0; }
.tpl .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.tpl .mini { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 8px; border-radius: var(--r-2); background: var(--surface-2); }
.tpl .mini i { display: block; height: 14px; border-radius: 3px; background: var(--surface); border: 1px solid var(--line); }
.tpl .mini i.w2 { grid-column: span 2; height: 34px; }
.tpl .mini i.w4 { grid-column: span 4; height: 20px; }
.tpl .mini i.acc { background: var(--accent-soft); border-color: var(--accent-line); }

/* dashboard list sheet */
.dl-li { display: flex; align-items: center; gap: var(--s-3); padding: 10px var(--s-2); border-radius: var(--r-2); cursor: pointer; min-height: 52px; }
.dl-li:hover { background: var(--surface-2); }
.dl-li.on { background: var(--accent-soft); }
.dl-li .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.dl-li.on .ic { background: var(--accent); color: var(--accent-ink); }

/* schedule list */
.sc-li { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--line); }
.sc-li:last-child { border-bottom: 0; }
.rcp { display: flex; flex-wrap: wrap; gap: 6px; }
.rcp .chip { height: 32px; padding-left: 4px; }

@container qapp (min-width: 720px) {
  .db-bar { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; }
  .db-bar .periods { margin: 0; padding: 0; }
  .db-bar .line2 { flex: 0 1 auto; }
  .db-bar .owner { flex: 0 1 auto; }
  .db-pick { max-width: 260px; }
  .db-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-auto-rows: 64px; grid-auto-flow: row dense; }
  .db-grid > .dw, .db-grid > .dw.half { grid-column: span var(--wt, 6); grid-row: span var(--h, 4); overflow: hidden; }
  .db-grid > .dw .dw-b { min-height: 0; overflow: auto; }
  .dw-add { grid-column: span 6; }
  .dk .val { font-size: var(--fs-2xl); }
  .kinds { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dw-move { display: none; }
}
@container qapp (min-width: 1024px) {
  .db-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-flow: row; }
  .db-grid > .dw, .db-grid > .dw.half { grid-column: var(--x1) / span var(--w); grid-row: var(--y1) / span var(--h); }
  .db-grid.edit { background-image: linear-gradient(to right, color-mix(in oklch, var(--accent) 7%, transparent) 1px, transparent 1px); background-size: calc((100% + var(--s-3)) / 12) 100%; }
  .dw-add { grid-column: 1 / -1; }
  .dw-ghost { grid-column: var(--x1) / span var(--w); grid-row: var(--y1) / span var(--h); }
  .dw.editing .dw-resize { display: block; position: absolute; right: 4px; bottom: 4px; width: 18px; height: 18px; cursor: nwse-resize; color: var(--accent); }
  .rb { grid-template-columns: 380px minmax(0, 1fr); align-items: start; }
  .rb-prev { position: sticky; top: 76px; }
  .rb-prev .dw { min-height: 420px; }
}

/* widget-level layout: donut legend beside the ring only when the widget is wide enough */
@container dwb (min-width: 440px) {
  .dn { flex-direction: row; align-items: center; gap: var(--s-5); }
}

/* nested scroll areas keep the wheel/finger at their ends while they overflow (q-contain, packages/ui/src/styles/app.css) */
.db-grid > .dw .dw-b { animation: q-contain-y linear both !important; animation-timeline: scroll(self block) !important; }
.db-bar .periods { animation: q-contain-x linear both !important; animation-timeline: scroll(self inline) !important; }
