/* BooksBat custom report builder (/report-builder.html) and the dashboard widget grid with KPIs. Solid colours only. */

/* ---------- builder ---------- */
.rb-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.rb-open { max-width: 420px; margin: 0 0 12px; }
.rb-open .field { margin: 0; }
.rb-layout { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 14px; align-items: start; }
.rb-panel { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.rb-sec { padding: 0; overflow: hidden; }
.rb-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; font-weight: 600; font-size: 14px; }
.rb-sec > summary::-webkit-details-marker { display: none; }
.rb-sec > summary::after { content: ''; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: -4px 4px 0 auto; transition: transform .12s; flex: none; }
.rb-sec[open] > summary::after { transform: rotate(-135deg); margin-top: 4px; }
.rb-sec > summary small { font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-size: 11.5px; }
.rb-sec > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rb-sec-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.rb-sec-body .field { margin: 0; }
.rb-sec-body select, .rb-sec-body input[type=text], .rb-sec-body input[type=number], .rb-sec-body input[type=date] { width: 100%; min-width: 0; }
.rb-desc { margin: 0; }
.rb-help { margin: 0; line-height: 1.45; }
.rb-cols { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rb-col { display: flex; align-items: center; gap: 4px; padding: 3px 4px 3px 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 13.5px; }
.rb-col.dragging { opacity: .5; }
.rb-col.over { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.rb-grip { cursor: grab; color: var(--muted); display: inline-flex; }
.rb-col-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; gap: 6px; }
.btn.icon.sm { width: 30px; padding: 0; }
.rb-calc { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.rb-calc .grid2 { gap: 8px; }
.rb-formula { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.rb-calc-tools { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.rb-calc-tools select { flex: 1; min-width: 0; }
.rb-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.rb-group-head { font-size: 12.5px; color: var(--text-2); }
.rb-cond { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; grid-template-areas: "field field remove" "op value value"; gap: 6px; align-items: center; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.rb-cond > :nth-child(1) { grid-area: field; } .rb-cond > :nth-child(2) { grid-area: op; } .rb-cond > :nth-child(3) { grid-area: value; } .rb-cond > :nth-child(4) { grid-area: remove; }
.rb-cond > * { min-width: 0; }
.rb-cond select, .rb-cond input { width: 100%; }
.rb-two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.rb-multi { min-height: 64px; }
.rb-row { display: flex; gap: 8px; align-items: flex-end; }
.rb-row > * { flex: 1; min-width: 0; }
.rb-row > .btn { flex: none; }
.rb-chart-types { align-self: flex-start; flex-wrap: wrap; }
.rb-chart-types button { display: inline-flex; align-items: center; gap: 5px; }
.rb-result { padding: 0; overflow: hidden; min-width: 0; min-height: 240px; }
.rb-result.loading .rv-scroll, .rb-result.loading .rb-chart { opacity: .55; transition: opacity .15s; }
.rb-chart { margin: 0; padding: 16px 18px 6px; border-bottom: 1px solid var(--border); }
.rb-chart figcaption { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; }
.rb-chart-empty { padding: 14px 18px; margin: 0; border-bottom: 1px solid var(--border); }
.rb-error { color: var(--danger); display: flex; align-items: center; justify-content: center; gap: 6px; }
.rb-table td:first-child { min-width: 140px; }

/* ---------- charts added for the builder and KPIs ---------- */
.viz-pie-box { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 18px; align-items: center; }
.viz-pie { max-width: 220px; }
.viz-slice { stroke: var(--surface); stroke-width: 2; outline: none; cursor: default; }
.viz-slice.on, .viz-slice:focus-visible { opacity: .85; }
.viz-pie-total { fill: var(--text); font-size: 15px; font-weight: 700; font-family: var(--font); font-variant-numeric: tabular-nums; }
.viz-pie-keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.viz-pie-keys li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 46px; gap: 8px; align-items: center; }
.viz-pie-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.viz-pie-keys b { font-variant-numeric: tabular-nums; }
.viz-pie-keys small { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.viz-spark { display: block; width: 100%; height: auto; overflow: visible; }
.viz-spark .viz-line { stroke-width: 2; }

/* ---------- dashboard widgets ---------- */
.dash-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: -4px 0 14px; }
.dash-bar .muted { font-size: 13px; }
.dash-bar .spacer { flex: 1; }
.dash.editing > .card, .dash.editing > .kpis { outline: 1px dashed var(--border-strong); outline-offset: 3px; }
.dash > .dash-w { position: relative; min-width: 0; }
.dash .w-3 { grid-column: span 3; } .dash .w-4 { grid-column: span 4; } .dash .w-5 { grid-column: span 5; } .dash .w-6 { grid-column: span 6; }
.dash .w-7 { grid-column: span 7; } .dash .w-8 { grid-column: span 8; } .dash .w-9 { grid-column: span 9; } .dash .w-12 { grid-column: span 12; }
.dash-w.dragging { opacity: .45; }
.dash-w.drop-before { box-shadow: -4px 0 0 var(--accent); }
.dash-w.drop-after { box-shadow: 4px 0 0 var(--accent); }
.dash-tools { display: none; align-items: center; gap: 2px; position: absolute; top: 6px; right: 6px; z-index: 4; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px; box-shadow: var(--shadow-sm); }
.dash.editing .dash-tools { display: flex; }
.dash-tools .btn { height: 28px; width: 28px; padding: 0; }
.dash-tools .dash-grip { cursor: grab; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; color: var(--muted); }
.dash-tools select { height: 28px; font-size: 12px; padding: 0 6px; width: auto; }
.dash-kpis-w { grid-column: span 12; }
.dash-kpis-w > .kpis { margin: 0; }

.kmw { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kmw-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.kmw-label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kmw-period { font-size: 12px; color: var(--muted); white-space: nowrap; }
.kmw-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kmw-value.empty { color: var(--muted); font-size: 18px; font-weight: 600; }
.kmw-delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.kmw-delta.good { color: var(--success); }
.kmw-delta.bad { color: var(--danger); }
.kmw-delta .i { width: 14px; height: 14px; }
.kmw-delta span { font-weight: 500; color: var(--muted); }
.kmw-target { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.kmw-track { height: 6px; border-radius: 3px; background: var(--viz-track); overflow: hidden; }
.kmw-fill { display: block; height: 100%; border-radius: 0 3px 3px 0; background: var(--viz-1); }
.kmw-fill.met { background: var(--viz-good); }
.kmw-spark { margin-top: 2px; }
.kmw-note { font-size: 12.5px; color: var(--muted); }

.rw { padding: 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.rw .rv-scroll { border: 1px solid var(--border); border-radius: var(--radius); }
.rw table.rpt { font-size: 13px; }
.rw-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.rw-foot { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }

.dash-gallery { display: flex; flex-direction: column; gap: 14px; }
.dash-gallery h4 { margin: 0 0 6px; font-size: 13px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.dash-gallery-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.dash-gallery-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.dash-gallery-item:hover, .dash-gallery-item:focus-visible { border-color: var(--accent); }
.dash-gallery-item b { font-size: 13.5px; }
.dash-gallery-item small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.dash-gallery-item[disabled] { opacity: .5; cursor: not-allowed; }

@media (max-width: 1100px) {
  .rb-layout { grid-template-columns: 1fr; }
  .dash .w-3 { grid-column: span 6; }
  .dash .w-4, .dash .w-5, .dash .w-6, .dash .w-7, .dash .w-8, .dash .w-9 { grid-column: span 12; }
}
@media (max-width: 760px) {
  .rb-open { max-width: none; }
  .rb-actions .btn { flex: 1 1 auto; }
  .viz-pie-box { grid-template-columns: 1fr; justify-items: center; }
  .viz-pie-keys { width: 100%; }
  .dash .w-3, .dash .w-4, .dash .w-5, .dash .w-6, .dash .w-7, .dash .w-8, .dash .w-9, .dash .w-12 { grid-column: span 12; }
  .dash-tools { position: static; margin: -6px -6px 8px auto; width: max-content; }
  .dash-tools .dash-grip, .dash-tools select { display: none; }
  .kmw-value { font-size: 22px; }
}
