/* Reports module: home (folders + list + data sources), builder (fields / columns / filters / sort / group / preview,
   calculated-field and save dialogs) and results (cards, chart, grouped table with subtotals). */
main:has(.reports-page) { max-width:1320px; }
.reports-page .head h1 { margin:.3rem 0; }
.small { font-size:.82rem; }
.reports-page details { background:none; border:0; border-radius:0; padding:0; margin:0; } /* marketing.css styles bare details */
.reports-page details summary { font-weight:400; }
.reports-page details p { margin:.3rem 0 0; }
.link-btn { background:none; border:0; padding:.25rem 0; color:var(--brand); cursor:pointer; font:inherit; text-align:left; text-decoration:underline; }
.link-btn.danger { color:#b91c1c; }
.icon-btn { background:#fff; border:1px solid var(--line); border-radius:4px; width:1.8rem; height:1.8rem; cursor:pointer; color:#374151; line-height:1; }
.icon-btn:disabled { opacity:.35; cursor:default; }
.icon-btn.danger { color:#b91c1c; }
.chip-btn { display:inline-block; border:1px solid var(--line); background:#fff; border-radius:999px; padding:.15rem .65rem; font-size:.82rem; cursor:pointer; color:#1f2937; text-decoration:none; }
.chip-btn.active { background:var(--brand); color:#fff; border-color:var(--brand); }
.star { background:none; border:0; font-size:1.15rem; cursor:pointer; color:#9ca3af; padding:0 .2rem; line-height:1; }
.star.on { color:#f59e0b; }

/* ---- home ---- */
.reports-home { display:grid; grid-template-columns:15rem minmax(0,1fr); gap:1.25rem; align-items:start; }
@media (max-width:860px) { .reports-home { grid-template-columns:1fr; } }
.rh-side { background:#fff; border:1px solid var(--line); border-radius:8px; padding:.8rem; display:grid; gap:.5rem; }
.rh-new { text-align:center; padding:.55rem; }
.rh-views { display:grid; }
.rh-view, .rh-folder-link { display:flex; justify-content:space-between; gap:.5rem; padding:.35rem .5rem; border-radius:5px; text-decoration:none; color:#1f2937; }
.rh-view:hover, .rh-folder-link:hover { background:#f1f5f9; }
.rh-view.active, .rh-folder.active .rh-folder-link { background:#e8eef7; font-weight:600; color:var(--brand); }
.count { color:var(--muted); font-size:.8rem; font-variant-numeric:tabular-nums; }
.rh-heading { font-size:.78rem; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin:.8rem 0 .3rem; }
.rh-folders, .rh-folders ul { list-style:none; margin:0; padding:0; }
.rh-folders ul { padding-left:1rem; }
.rh-folder { display:flex; align-items:center; gap:.2rem; }
.rh-folder .rh-folder-link { flex:1; min-width:0; }
.rh-folder .rh-folder-link span:first-child { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.rh-more { position:relative; }
.rh-more > summary { list-style:none; cursor:pointer; padding:.1rem .4rem; border-radius:4px; color:var(--muted); }
.rh-more > summary::-webkit-details-marker { display:none; }
.rh-more[open] > summary { background:#f1f5f9; }
.rh-menu { position:absolute; right:0; z-index:20; background:#fff; border:1px solid var(--line); border-radius:6px; box-shadow:0 8px 24px rgba(0,0,0,.12); padding:.6rem; min-width:15rem; display:grid; gap:.35rem; text-align:left; }
.rh-menu form { margin:0; }
.rh-move { display:flex; gap:.35rem; align-items:end; }
.rh-move label { flex:1; font-size:.85rem; }
.rh-newfolder summary { cursor:pointer; color:var(--brand); padding:.3rem .5rem; }
.rh-search { min-width:16rem; }
.rh-table { border:1px solid var(--line); border-radius:8px; overflow:visible; }
.rh-table th { font-size:.8rem; color:var(--muted); font-weight:600; background:#f8fafc; }
.rh-table .col-star { width:2rem; }
.rh-table .col-actions { white-space:nowrap; text-align:right; }
.rh-table .row-actions { display:flex; gap:.6rem; align-items:center; justify-content:flex-end; }
.rh-name { font-weight:600; }
.rh-source { white-space:nowrap; font-size:.88rem; }
.rh-sources { display:grid; grid-template-columns:repeat(auto-fill, minmax(14rem, 1fr)); gap:.75rem; }
.rh-source-card { display:grid; gap:.2rem; background:#fff; border:1px solid var(--line); border-radius:8px; padding:.85rem; text-decoration:none; color:#1f2937; }
.rh-source-card:hover { border-color:var(--brand); box-shadow:0 2px 8px rgba(29,53,87,.12); }
.rh-source-card .icon { font-size:1.4rem; }
.rh-source-card small { color:var(--muted); }
.rh-source-card .go { color:var(--brand); font-weight:600; font-size:.85rem; margin-top:.3rem; }
.rh-source-card.later { opacity:.55; background:#f8fafc; border-style:dashed; }

/* ---- builder ---- */
.rb-top { display:flex; justify-content:space-between; align-items:center; gap:1rem; flex-wrap:wrap; margin-bottom:.6rem; }
.rb-title { margin:0; font-size:1.4rem; }
.rb-sub { margin:.1rem 0 0; }
.rb-top-actions { display:flex; gap:.5rem; }
.rb-grid { display:grid; grid-template-columns:16rem minmax(0,1fr); gap:1rem; align-items:start; }
@media (max-width:900px) { .rb-grid { grid-template-columns:1fr; } }
.rb-fields { background:#fff; border:1px solid var(--line); border-radius:8px; padding:.8rem; position:sticky; top:.5rem; max-height:calc(100vh - 1rem); overflow:auto; }
.rb-fields h2 { font-size:.8rem; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin:.4rem 0; }
.rb-field-list { list-style:none; margin:0 0 .6rem; padding:0; display:grid; gap:.2rem; }
.rb-field { width:100%; display:flex; gap:.4rem; align-items:center; background:#fff; border:1px solid var(--line); border-radius:5px; padding:.3rem .45rem; cursor:pointer; font:inherit; font-size:.88rem; text-align:left; }
.rb-field:hover:not(:disabled) { border-color:var(--brand); background:#f5f8fc; }
.rb-field.used { opacity:.5; cursor:default; }
.rb-calc { display:grid; gap:.1rem; }
.rb-calc-actions { display:flex; gap:.6rem; font-size:.8rem; padding-left:.3rem; }
.ftype { font-size:.65rem; text-transform:uppercase; letter-spacing:.03em; border-radius:3px; padding:.05rem .3rem; background:#eef2f7; color:#475569; white-space:nowrap; }
.ftype-money { background:#dcfce7; color:#166534; } .ftype-number { background:#e0f2fe; color:#075985; } .ftype-date { background:#fef3c7; color:#92400e; }
.ftype-boolean { background:#ede9fe; color:#5b21b6; } .ftype-image { background:#fce7f3; color:#9d174d; } .ftype-calc { background:#1d3557; color:#fff; }
.rb-main { display:grid; gap:.8rem; min-width:0; }
.rb-card { background:#fff; border:1px solid var(--line); border-radius:8px; padding:.8rem 1rem; min-width:0; }
.rb-card h2 { font-size:1rem; margin:0 0 .6rem; }
.rb-two { display:grid; grid-template-columns:1fr 1fr; gap:.8rem; }
@media (max-width:760px) { .rb-two { grid-template-columns:1fr; } }
.rb-columns { list-style:none; margin:0; padding:0; display:grid; gap:.4rem; }
.rb-col { border:1px solid var(--line); border-radius:6px; padding:.4rem .5rem; background:#fbfcfe; }
.rb-col.dragging { opacity:.5; border-style:dashed; }
.rb-col-head { display:flex; gap:.5rem; align-items:center; flex-wrap:wrap; }
.rb-col-head .grip { cursor:grab; color:#9ca3af; letter-spacing:-2px; user-select:none; }
.rb-col-label { flex:1 1 12rem; width:auto !important; min-width:8rem; }
.rb-col-move { display:flex; gap:.25rem; margin-left:auto; }
.rb-col-opts summary { cursor:pointer; color:var(--brand); font-size:.82rem; margin-top:.2rem; padding-left:1.4rem; }
.rb-opts-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(10rem, 1fr)); gap:.5rem .8rem; margin:.4rem 0; align-items:end; }
.rb-opts-grid label { display:grid; gap:.15rem; font-size:.82rem; color:#374151; }
.rb-opts-grid input[type=number] { width:100%; padding:.4rem; border:1px solid var(--line); border-radius:4px; }
.rb-inline { display:inline-flex !important; gap:.35rem; align-items:center; font-size:.88rem; white-space:nowrap; }
.rb-row { display:flex; flex-wrap:wrap; gap:.4rem; align-items:center; margin-bottom:.4rem; }
.rb-row select, .rb-row input { width:auto; min-width:8rem; }
.rb-row input[type=date], .rb-row input[type=number], .rb-row input[type=text] { padding:.4rem; border:1px solid var(--line); border-radius:4px; }
.rb-match { margin:.2rem 0 .5rem; }
.rb-match select { width:auto; }
.rb-daterange { border:1px solid var(--line); border-radius:6px; margin-top:.7rem; padding:.4rem .7rem; }
.rb-summary { margin-top:.5rem; }
.rb-preview-card { overflow:hidden; }
.rb-notice { margin:.4rem 0; }
.rb-dialog { border:0; border-radius:10px; padding:1.1rem 1.25rem; width:min(44rem, 94vw); box-shadow:0 20px 50px rgba(0,0,0,.25); }
.rb-dialog::backdrop { background:rgba(15,23,42,.45); }
.rb-dialog h2 { margin:0 0 .7rem; font-size:1.15rem; }
.rb-dialog .stack { max-width:none; margin-bottom:.6rem; }
.rb-dialog-actions { display:flex; justify-content:flex-end; gap:.5rem; margin-top:.8rem; }
.rb-save-dialog { width:min(30rem, 94vw); }
.calc-formula textarea { font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:.95rem; }
.calc-status { margin:.25rem 0 .5rem; font-size:.85rem; color:var(--muted); }
.calc-status.ok { color:#166534; } .calc-status.error { color:#b91c1c; }
.calc-chips { display:flex; flex-wrap:wrap; gap:.3rem; margin-bottom:.45rem; }
.chip-btn.field { background:#eef4ff; border-color:#c7d7f5; color:var(--brand); }
.chip-btn.op { font-family:ui-monospace, monospace; min-width:2rem; }
.chip-btn.fn { background:#f5f3ff; border-color:#ddd6fe; color:#5b21b6; font-weight:600; }
.calc-scope { border:1px solid var(--line); border-radius:6px; display:flex; gap:1.2rem; flex-wrap:wrap; padding:.4rem .7rem; }

/* ---- results ---- */
.rr-head h1 { display:flex; align-items:center; gap:.4rem; }
.rr-sub { margin:0; }
.rr-dates { display:flex; gap:.6rem; align-items:center; flex-wrap:wrap; background:#fff; border:1px solid var(--line); border-radius:8px; padding:.5rem .8rem; margin:.6rem 0; }
.rr-dates input { padding:.35rem; border:1px solid var(--line); border-radius:4px; }
.rr-header-text, .rr-footer-text { background:#fff; border-left:3px solid var(--brand); padding:.4rem .8rem; margin:.6rem 0; }
.rr-cards { display:grid; grid-template-columns:repeat(auto-fit, minmax(11rem, 1fr)); gap:.7rem; margin:.8rem 0; }
.rr-card { background:#fff; border:1px solid var(--line); border-radius:8px; padding:.7rem .9rem; display:grid; gap:.15rem; }
.rr-card-label { font-size:.78rem; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; }
.rr-card-value { font-size:1.45rem; font-variant-numeric:tabular-nums; color:var(--brand); }
.rr-chart { background:#fff; border:1px solid var(--line); border-radius:8px; padding:.7rem 1rem; margin-bottom:.8rem; }
.rr-chart-head { display:flex; justify-content:space-between; align-items:center; gap:1rem; flex-wrap:wrap; }
.rr-chart-head h2 { font-size:1rem; margin:0; }
.rr-chart-switch { display:flex; gap:.3rem; }
.report-chart-svg { width:100%; max-height:300px; display:block; margin-top:.4rem; }
.report-chart-svg .grid { stroke:#e5e7eb; stroke-width:1; }
.report-chart-svg .axis { font-size:11px; fill:#6b7280; }
.report-table-wrap { background:#fff; border:1px solid var(--line); border-radius:8px; }
.report-table { font-size:.88rem; }
.report-table th, .report-table td { padding:.35rem .55rem; vertical-align:middle; }
.report-table thead th { background:#f8fafc; font-size:.78rem; color:#475569; position:sticky; top:0; }
.report-table .num { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; }
.report-table .rc-image { width:52px; }
.report-table .stacked { font-size:.8rem; color:var(--muted); }
.report-table tr.rt-group th { background:#eef2f7; color:var(--brand); font-weight:700; text-align:left; }
.report-table tr.rt-group.rt-level-1 th { background:#f5f7fa; padding-left:1.4rem; }
.report-table tr.rt-group.rt-level-2 th { background:#fafbfc; padding-left:2.4rem; font-weight:600; }
.report-table tr.rt-subtotal th, .report-table tr.rt-subtotal td { background:#f8fafc; font-weight:600; border-top:1px solid #cbd5e1; }
.report-table tr.rt-subtotal.rt-level-1 th { padding-left:1.4rem; } .report-table tr.rt-subtotal.rt-level-2 th { padding-left:2.4rem; }
.report-table tr.rt-summary th { font-weight:600; }
.report-table tr.rt-summary.rt-level-1 th { padding-left:1.4rem; } .report-table tr.rt-summary.rt-level-2 th { padding-left:2.4rem; }
.report-table tr.rt-grand th, .report-table tr.rt-grand td { background:#1d3557; color:#fff; font-weight:700; }
.report-table th.rt-label { text-align:left; white-space:nowrap; }
.report-table th.rt-label.num .rt-label-text { float:left; margin-right:1rem; }
@media print {
  main:has(.reports-page) { max-width:none; margin:0; }
  .report-table thead th { position:static; }
  .rr-chart, .rr-card, .report-table-wrap { break-inside:avoid; }
}

/* Results: export menu, email / schedule dialogs, print view */
.rr-export { display:inline-block; }
.rr-export > summary.btn { color:inherit; padding:.45rem .9rem; background:var(--btn-secondary-bg, #fff); }
.rr-export .rh-menu { right:0; left:auto; min-width:11rem; z-index:20; }
.rr-schedule-form label.stack { margin-bottom:.5rem; }
.rr-schedule-remove { margin-top:.75rem; text-align:right; }
.report-print .rr-cards { margin:.5rem 0 1rem; }
@media print {
  .report-print .rr-table-wrap { overflow:visible; }
  .report-print table { font-size:9pt; }
  .report-print tr { break-inside:avoid; }
}
