/* ============================================================
   Reporting module — dashboards, widgets, builder, charts
   ============================================================ */
:root {
  --rp-c1: #0e7c74; --rp-c2: #e0563a; --rp-c3: #4c6ef5; --rp-c4: #d69e2e;
  --rp-c5: #8b5cf6; --rp-c6: #2f9e44; --rp-c7: #d6336c; --rp-c8: #6b7c85;
}
:root[data-theme="dark"] {
  --rp-c1: #2ad6c7; --rp-c2: #ff8b6b; --rp-c3: #7c93ff; --rp-c4: #fbbf24;
  --rp-c5: #a78bfa; --rp-c6: #51cf66; --rp-c7: #f06595; --rp-c8: #9fb1b8;
}

/* inputs */
.rp-in {
  width: 100%; padding: 8px 10px; font-size: 13px; color: var(--text-primary);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-body); min-height: 36px;
}
.rp-in:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-dim); }
.rp-lbl { display: block; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 5px; }
.rp-field { margin-bottom: 14px; }
.rp-row { display: flex; gap: 8px; align-items: center; }
.rp-row > * { min-width: 0; }
.rp-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.rp-toolbar .sp { flex: 1; }
.rp-range { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rp-range .rp-in { width: auto; }

/* cards list */
.rp-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.rp-card {
  background: var(--bg-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
  padding: 18px 20px; cursor: pointer; transition: box-shadow .15s, transform .15s; display: flex; flex-direction: column; gap: 8px;
  border: 1px solid transparent;
}
.rp-card:hover { box-shadow: var(--shadow-md); border-color: var(--border); }
.rp-card h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); margin: 0; }
.rp-card p { font-size: 12.5px; color: var(--text-muted); margin: 0; line-height: 1.45; flex: 1; }
.rp-card .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 11.5px; color: var(--text-muted); }
.rp-section-h { font-family: var(--font-display); font-size: 16px; font-weight: 600; margin: 28px 0 14px; color: var(--text-primary); display: flex; justify-content: space-between; align-items: center; }
.rp-section-h:first-child { margin-top: 0; }

/* dashboard grid */
.rp-grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 88px; grid-auto-flow: dense; gap: 16px; }
.rp-widget {
  background: var(--bg-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; position: relative;
  border: 1px solid transparent;
}
.rp-widget.edit { border: 1px dashed var(--border-hover); }
.rp-widget.dragover { border-color: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-dim); }
.rp-w-h { display: flex; align-items: center; gap: 6px; padding: 12px 14px 4px; min-height: 36px; }
.rp-w-t { font-size: 13px; font-weight: 600; color: var(--text-secondary); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-w-act { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; position: absolute; right: 8px; top: 6px; background: var(--bg-surface); border-radius: 8px; padding: 1px 2px; z-index: 2; }
.rp-widget.edit .rp-w-act { position: static; padding: 0; }
.rp-widget:hover .rp-w-act, .rp-widget.edit .rp-w-act { opacity: 1; }
.rp-ib { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 3px 6px; border-radius: 6px; font-size: 13px; line-height: 1; }
.rp-ib:hover { background: var(--bg-hover); color: var(--text-primary); }
.rp-w-b { flex: 1; min-height: 0; padding: 4px 14px 12px; overflow: hidden; position: relative; }
.rp-w-b.kpi { display: flex; align-items: center; }
.rp-w-sub { font-size: 11px; color: var(--text-muted); padding: 0 14px 8px; }
.rp-handle { cursor: grab; color: var(--text-muted); font-size: 14px; padding: 0 2px; }
.rp-add-tile {
  display: flex; align-items: center; justify-content: center; border: 2px dashed var(--border); border-radius: var(--radius-md);
  color: var(--text-muted); cursor: pointer; font-size: 14px; grid-column: span 4; grid-row: span 2; background: transparent;
}
.rp-add-tile:hover { border-color: var(--cyan); color: var(--cyan-text); background: var(--cyan-dim); }
.rp-size { display: flex; gap: 4px; align-items: center; font-size: 11px; color: var(--text-muted); }
.rp-size select { min-height: 26px !important; padding: 2px 6px !important; font-size: 11px !important; width: auto !important; }

/* chart internals */
.rp-svg { display: block; font-family: var(--font-body); overflow: visible; }
.rp-grid { stroke: var(--border); stroke-width: 1; }
.rp-ax { font-size: 11px; fill: var(--text-muted); }
.rp-ax-l { fill: var(--text-secondary); }
.rp-val { font-size: 11px; font-weight: 600; fill: var(--text-primary); }
.rp-val.rp-on { fill: #fff; }
.rp-val-in { font-size: 11px; font-weight: 600; fill: #fff; }
.rp-track { fill: var(--bg-elevated); }
.rp-donut-v { font-size: 22px; font-weight: 700; fill: var(--text-primary); font-family: var(--font-display); }
.rp-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--text-secondary); padding-bottom: 6px; }
.rp-legend span { display: inline-flex; align-items: center; gap: 5px; }
.rp-dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
svg [data-tip] { cursor: pointer; transition: opacity .1s; }
svg [data-tip]:hover { opacity: .78; }
.rp-hit:hover { fill: var(--cyan-dim); }
.rp-scroll { overflow: auto; }
.rp-empty { display: flex; align-items: center; justify-content: center; height: 100%; min-height: 80px; color: var(--text-muted); font-size: 12.5px; text-align: center; padding: 10px; }
.rp-tooltip {
  position: fixed; z-index: 3000; pointer-events: none; opacity: 0; transition: opacity .08s;
  background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); border-radius: 8px; padding: 8px 11px; font-size: 12px; max-width: 280px;
}
.rp-tip-h { font-weight: 600; margin-bottom: 4px; }
.rp-tip-r { display: flex; align-items: center; gap: 6px; }
.rp-tip-r b { margin-left: auto; padding-left: 14px; }
.rp-donut { display: flex; align-items: center; gap: 18px; height: 100%; }
.rp-donut.col { flex-direction: column; align-items: stretch; gap: 8px; }
.rp-donut.col svg { align-self: center; }
.rp-leg { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; overflow: auto; max-height: 100%; }
.rp-leg-row { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.rp-leg-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-leg-row b { color: var(--text-primary); min-width: 34px; text-align: right; }
.rp-leg-v { color: var(--text-muted); min-width: 42px; text-align: right; font-size: 11.5px; }

/* KPI */
.rp-kpis { display: flex; gap: 26px; flex-wrap: wrap; width: 100%; align-items: flex-end; }
.rp-kpi-v { font-family: var(--font-display); font-size: 30px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.rp-kpi-l { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.rp-delta { font-size: 11.5px; font-weight: 600; margin-top: 4px; }
.rp-delta span { font-weight: 400; color: var(--text-muted); }
.rp-delta.up, .rp-mini.up { color: #2f9e44; }
.rp-delta.down, .rp-mini.down { color: var(--red); }
.rp-delta.flat { color: var(--text-muted); }
.rp-mini { font-size: 10.5px; font-weight: 600; margin-left: 4px; }

/* table */
.rp-table-wrap { overflow: auto; max-height: 100%; }
.rp-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.rp-table th { position: sticky; top: 0; background: var(--bg-surface); text-align: left; padding: 7px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); border-bottom: 1px solid var(--border); cursor: pointer; white-space: nowrap; z-index: 1; }
.rp-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); color: var(--text-secondary); vertical-align: top; }
.rp-table td.num, .rp-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.rp-table tbody tr:hover td { background: var(--bg-hover); }
.rp-note { font-size: 11.5px; color: var(--text-muted); padding: 6px 2px 0; }

/* builder modal */
.rp-modal { max-width: 1180px !important; width: 100%; }
.rp-editor { display: grid; grid-template-columns: 400px minmax(0, 1fr); gap: 0; min-height: 520px; }
.rp-editor-l { padding: 18px 20px; border-right: 1px solid var(--border); max-height: 72vh; overflow-y: auto; }
.rp-editor-r { padding: 18px 22px; display: flex; flex-direction: column; min-width: 0; max-height: 72vh; overflow-y: auto; }
.rp-step { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--cyan-text); margin: 20px 0 10px; display: flex; align-items: center; gap: 8px; }
.rp-step:first-child { margin-top: 0; }
.rp-step i { width: 18px; height: 18px; border-radius: 50%; background: var(--cyan-dim); color: var(--cyan-text); font-style: normal; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; }
.rp-preview { flex: 1; min-height: 300px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 14px; position: relative; overflow: hidden; }
.rp-preview-h { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; align-items: center; }
.rp-err { color: var(--red); font-size: 12.5px; background: var(--red-dim); padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; }
.rp-chartpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
.rp-chartbtn { border: 1px solid var(--border); background: var(--bg-surface); border-radius: 8px; padding: 8px 6px; font-size: 11.5px; color: var(--text-secondary); cursor: pointer; text-align: center; line-height: 1.25; }
.rp-chartbtn b { display: block; font-size: 17px; font-weight: 400; color: var(--text-muted); margin-bottom: 2px; }
.rp-chartbtn:hover:not(.off) { border-color: var(--cyan); }
.rp-chartbtn.on { border-color: var(--cyan); background: var(--cyan-dim); color: var(--cyan-text); }
.rp-chartbtn.on b { color: var(--cyan-text); }
.rp-chartbtn.off { opacity: .38; cursor: not-allowed; }
.rp-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--bg-elevated); color: var(--text-secondary); margin: 2px 4px 2px 0; }
.rp-chip.dim { background: var(--cyan-dim); color: var(--cyan-text); }
.rp-chip.num { background: var(--lime-dim); color: var(--lime); }
.rp-chip.date { background: var(--purple-dim); color: var(--purple); }
.rp-src { background: var(--bg-elevated); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }
.rp-src code { font-family: var(--font-mono); font-size: 11.5px; color: var(--cyan-text); }
.rp-list-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.rp-cols { max-height: 210px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; }
.rp-col { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; font-size: 12.5px; }
.rp-col:hover { background: var(--bg-hover); }
.rp-col label { flex: 1; display: flex; gap: 8px; align-items: center; cursor: pointer; }

/* dataset explorer */
.rp-ds { background: var(--bg-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); padding: 16px 18px; }
.rp-ds h3 { margin: 0 0 2px; font-size: 15px; }
.rp-ds .tbl { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); }

@media (max-width: 900px) {
  .rp-editor { grid-template-columns: 1fr; }
  .rp-editor-l { border-right: none; border-bottom: 1px solid var(--border); max-height: none; }
  .rp-editor-r, .rp-editor-l { max-height: none; }
  .rp-grid-12 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .rp-grid-12 > .rp-widget { grid-column: span 6 !important; }
}
@media (max-width: 560px) { .rp-grid-12 > .rp-widget { grid-column: span 6 !important; } .rp-kpi-v { font-size: 24px; } }

/* print / PDF export */
@media print {
  .sidebar, .topbar, .mobile-topbar, .rp-noprint, .rp-w-act, .toast-container, .sidebar-overlay { display: none !important; }
  .content-area, .main-content { padding: 0 !important; margin: 0 !important; overflow: visible !important; height: auto !important; }
  body, html { overflow: visible !important; height: auto !important; background: #fff !important; }
  .rp-widget { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
  .rp-grid-12 { grid-auto-rows: 80px; }
  .rp-print-title { display: block !important; }
}
.rp-print-title { display: none; margin-bottom: 12px; }

/* edit mode: keep the title readable on narrow widgets by putting controls on their own row */
.rp-widget.edit .rp-w-h { flex-wrap: wrap; row-gap: 2px; }
.rp-widget.edit .rp-w-t { flex: 1 1 60px; }
.rp-widget.edit .rp-w-act { flex-basis: 100%; justify-content: flex-end; }

/* list tables (KPI / Reports) */
.rp-tablecard { background: var(--bg-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); padding: 4px 8px 8px; overflow-x: auto; }
.rp-tablecard .data-table { width: 100%; }
.rp-tablecard .num { text-align: right; font-variant-numeric: tabular-nums; }
.rp-clickrow { cursor: pointer; }
.rp-tname { font-weight: 600; color: var(--text-primary); }
.rp-tdesc { font-size: 12px; color: var(--text-muted); margin-top: 2px; max-width: 520px; }
