/* Sezione Report: modulo di generazione, archivio, pagina di un report e foglio.
   Usa i token di app.css (temi chiaro e scuro) e le classi .statement* del rendiconto, con il suo blocco di stampa.
   Prefissi: .rep-* per la pagina, .report-* per il foglio. */

.rpt-body, .rep-tab, .rep-run { min-width: 0; }
.rep-tab [hidden], .rep-run [hidden] { display: none !important; }
.rep-error { color: var(--danger); max-width: 28ch; overflow-wrap: anywhere; }

/* ---- Modulo di generazione ---- */
.rep-gen { display: grid; grid-template-columns: minmax(320px, 620px) minmax(260px, 380px); gap: 18px; align-items: start; }
@media (max-width: 960px) { .rep-gen { grid-template-columns: minmax(0, 1fr); } }
.rep-form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.rep-form .card-header { margin-bottom: 0; }
.rep-form .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rep-form .field > span:first-child { font-weight: 600; font-size: 12.5px; color: var(--muted); }
.rep-form .field.error > span:first-child { color: var(--danger); }
.rep-form input[type="date"] { max-width: 220px; }
.rep-form select { max-width: 100%; }
.rep-type .segmented, .rep-scope .segmented { align-self: flex-start; max-width: 100%; flex-wrap: wrap; }
.rep-scope-msg { display: block; color: var(--danger); font-size: 12.5px; font-weight: 550; line-height: 1.35; }
.rep-scope.error > span:first-child { color: var(--danger); }
.rep-options { margin: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.rep-options legend { padding: 0 6px; color: var(--muted); font-size: 12.5px; font-weight: 550; }
.rpt-check { align-items: flex-start; }
.rpt-check input { margin-top: 3px; }
.rpt-check > span { display: flex; flex-direction: column; gap: 2px; }
.rep-advanced { margin-top: 4px; }
.rep-advanced > summary { padding: 4px 0; font-weight: 550; cursor: pointer; }
.rep-advanced .field { margin-top: 8px; }
.rep-side { min-width: 0; position: sticky; top: 56px; }
@media (max-width: 960px) { .rep-side { position: static; } }
.rep-side p { margin: 8px 0 0; }
.rep-internal { color: var(--warn); }

/* Scelta multipla: la tendina sopra, i chip scelti sotto. */
.rep-chip-picker { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.rpt-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.rpt-chips:empty { display: none; }
.rep-chip { max-width: 100%; }
.rep-chip > span { overflow-wrap: anywhere; }

/* Ultimi report */
.rep-recent { margin-top: 18px; }
.rep-recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rep-recent-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.rep-recent-list li:last-child { border-bottom: none; }
.rep-recent-what { color: var(--muted); font-size: 13px; flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }

/* ---- Archivio ---- */
.rep-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin-bottom: 14px; }
.rep-filter { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.rep-filter > span { color: var(--muted); font-size: 12px; }
.rep-filter select { min-width: 150px; }
.rep-schedule-chip { align-self: flex-end; }
.rep-row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.rep-actions-col { text-align: right; white-space: nowrap; }
.rep-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-top: 12px; }
.rep-pager .actions { align-items: center; }
@media (max-width: 760px) { .rep-pager { flex-direction: column; align-items: flex-start; } }

/* ---- Pagina di un report ---- */
.rep-run-head .page-header { margin-bottom: 8px; }
.rep-run-facts { margin: 0 0 16px; overflow-wrap: anywhere; }
.rep-progress { display: flex; flex-direction: column; gap: 8px; max-width: 640px; }
.rep-progress-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.rep-progress-text { color: var(--text); }
.rep-toolbar { align-items: center; max-width: 1040px; }
.rep-toolbar .rep-pdf-info { margin-left: auto; overflow-wrap: anywhere; }
.rep-deliveries { max-width: 1040px; margin: 16px auto 0; }

/* ---- Foglio ---- */
.report-sheet { max-width: 1040px; }
.report-head { display: flex; flex-direction: column; gap: 14px; }
.report-brand { display: flex; align-items: center; gap: 14px; }
.report-brand h1 { margin: 0; }
.report-logo { flex: none; width: 48px; height: 48px; }
.report-logo.dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .report-logo.light { display: none; }
  :root:not([data-theme="light"]) .report-logo.dark { display: block; }
}
:root[data-theme="dark"] .report-logo.light { display: none; }
:root[data-theme="dark"] .report-logo.dark { display: block; }
.report-companies { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 18px; font-size: 11.5px; color: var(--muted); }
.report-company strong { display: block; color: var(--text); font-size: 12px; margin-bottom: 2px; }
.report-company-line { overflow-wrap: anywhere; }
.report-head .statement-meta { margin-top: 0; }
.report-kpis { margin-bottom: 14px; }
.report-kpis .kpi.estimate .value { font-style: italic; }
.report-kpis .kpi.tone-ok .value { color: var(--ok); }
.report-kpis .kpi.tone-warn .value { color: var(--warn); }
.report-kpis .kpi.tone-danger .value { color: var(--danger); }
.report-kpis .kpi.tone-info .value { color: var(--info); }
.report-table { margin: 6px 0 14px; }
.report-table h3 { margin-top: 12px; }
.report-line { display: block; }
.report-line.strong { font-weight: 600; }
.report-line.sub { color: var(--muted); font-size: 0.92em; }
.report-note { margin: 4px 0 0; }
.report-text { margin: 8px 0; }
.rep-est { font-style: italic; }
.rep-est .badge { font-style: normal; }
th.rep-est { font-style: italic; }
.report-section.page-break { break-before: page; }
.report-notes ul { margin: 4px 0 0; }
.report-empty { margin: 16px 0; }
.report-foot { display: flex; flex-direction: column; gap: 4px; }
.report-sheet .statement-table td, .report-sheet .statement-table th { vertical-align: top; }
@media (max-width: 760px) {
  .report-brand { align-items: flex-start; }
  .report-sheet .kpis { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
}

/* ---- Stampa: solo il foglio ---- */
@media print {
  .rep-run-head, .rep-deliveries, body:has(.report-sheet) .tabs, body:has(.report-sheet) .page-header { display: none !important; }
  .report-sheet { max-width: none; }
  .report-logo.light { display: block !important; }
  .report-logo.dark { display: none !important; }
  .report-kpis .kpi { break-inside: avoid; box-shadow: none; }
  .report-table { break-inside: auto; }
  .report-section { break-inside: auto; }
  .report-companies { font-size: 9px; }
}
.page-header > .button[hidden] { display: none; }
