/* The Reports page: report tabs lead, one row of filters, one results card (DESIGN.md "Page structure").
   Generic controls (tabs, fields, segmented, switch, picker, alerts, figures, tables) are in ui.css. */
.report-type-select { display: none; }
.report-form { display: block; }
.report-error { flex-basis: 100%; margin: 0; color: var(--error); font-size: 13px; line-height: 1.46; }

/* the filter row */
.report-filters { position: relative; margin: 0 0 24px; }
.report-filter-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 16px; }
.report-filter-row > .ui-field:first-child { flex: 1 1 260px; max-width: 420px; }
.report-period { display: flex; flex: 1 1 320px; flex-wrap: wrap; align-items: flex-start; gap: 8px 16px; min-width: 0; }
.report-period > .ui-field { flex: 1 1 220px; }
.report-custom { display: flex; flex: 1 1 320px; gap: 16px; }
.report-custom > .ui-field { flex: 1 1 0; min-width: 130px; }
.js .report-custom[data-custom=false] { display: none; }
.report-history { margin-inline-start: auto; }
.report-reset { align-self: flex-end; display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px; color: var(--muted); font-size: 15px; font-weight: 500; }
.report-reset:hover { background: var(--grey-100); color: var(--ink); text-decoration: none; }
.report-more-filters { margin-top: 16px; }
.report-more-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; align-items: start; padding: 4px 18px 18px; }
.report-switch-sheet { display: none !important; }
.report-filters > noscript .button { margin-top: 16px; }

/* phone-only parts */
.report-summary, .report-scrim, .report-sheet-head, .report-sheet-foot { display: none; }

/* the results card */
.report-results { position: relative; margin: 0; padding: 24px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); box-shadow: 0 1px 2px #253d380d; }
.report-card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px 24px; }
.report-card-title { flex: 1 1 360px; min-width: 0; }
.report-card-title h2 { margin: 0 0 4px; font-size: 19px; font-weight: 650; line-height: 1.3; }
.report-scope { margin: 0 0 8px; color: var(--ink); font-size: 15px; line-height: 1.5; }
.report-describe { margin: 0; max-width: 720px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.report-card-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.report-csv { gap: 8px; }
.report-results .ui-alert { margin-top: 16px; }
.report-results .report-failed { margin: 0 0 16px; justify-content: space-between; }

/* Income, expenses and profit read as one sum; only the profit figure carries the breakdown, on phones */
.report-figures { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 16px; margin: 16px 0 0; }
.report-figures .ui-figure-detail { display: none; }
.report-op { color: var(--muted); font-size: 24px; line-height: 1; }

/* the statement */
.report-sheet { margin: 16px -24px 0; overflow-x: auto; }
.report-sheet .table-scroll { border-radius: 0; }
.report-sheet-table :is(th, td) { padding-inline: 24px; }
.report-sheet-table tr.group th { padding-top: 20px; padding-bottom: 8px; border-top: 0; color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.report-sheet-table tbody tr.group + tr :is(th, td) { border-top: 0; }
.report-sheet-table tr.total :is(th, td), .report-sheet-table tr.closing :is(th, td) { font-weight: 600; }
.report-sheet-table tr.closing.rule :is(th, td) { border-top: 2px solid var(--ink); }
.report-sheet-table tr.hint td { color: var(--muted); }
.report-code { color: var(--muted); font-weight: 400; }
.report-corrections { margin: 8px 0 0; scroll-margin-top: 24px; }
.report-corrections .report-section { margin: 16px -24px 0; border: 0; border-radius: 0; background: transparent; }
.report-corrections .report-section-head { padding: 12px 24px; }
.report-corrections .section-count { display: none; }
.report-corrections .financial-report-table thead th { background: var(--primary-50); color: var(--ink); font-size: 14px; }
.report-corrections .financial-report-table :is(th, td) { padding: 12px 24px; font-size: 14px; }

.report-ledger-head { display: flex; align-items: baseline; gap: 12px; margin: 24px 0 0; }
.report-ledger-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.report-muted { color: var(--muted); font-size: 13px; }
.report-ledger .ui-table { min-width: 1100px; }
.report-results .empty-state { margin: 16px 0 0; }
.report-foot { margin: 24px -24px -24px; padding: 14px 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.5; }
.report-body + .report-foot { margin-top: 0; }

/* refreshing: the old figures stay, dimmed, under a progress bar, until the new ones arrive */
.report-status { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.report-status:empty { display: none; }
.report-progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; overflow: hidden; opacity: 0; pointer-events: none; }
.report-progress::before { content: ""; position: absolute; top: 0; bottom: 0; width: 33%; background: var(--accent); }
.report-form.htmx-request .report-progress { opacity: 1; }
.report-form.htmx-request .report-progress::before { animation: report-progress 1.2s linear infinite; }
.report-form.htmx-request .report-body, .report-form.htmx-request .empty-state { opacity: .55; }
@keyframes report-progress { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
@media (prefers-reduced-motion: reduce) { .report-form.htmx-request .report-progress::before { animation: none; width: 100%; opacity: .4; } }

@media (max-width: 1000px) {
  .report-filter-row > .ui-field:first-child, .report-period { max-width: none; }
  .report-history { margin-inline-start: 0; }
}

@media (max-width: 640px) {
  body:has(.report-form) h1 { font-size: 30px; }
  .js .report-tabs { display: none; }
  .js .report-type-select { display: block; margin: 0 0 16px; }

  .js .report-summary { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; margin: 0 0 16px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font-size: 15px; text-align: left; cursor: pointer; }
  .report-summary-icon .ui-icon { width: 18px; height: 18px; color: var(--muted); }
  .report-summary-text { display: flex; flex: 1; flex-direction: column; min-width: 0; line-height: 1.4; }
  .report-summary-text strong { font-weight: 600; }
  .report-summary-text span { color: var(--muted); font-size: 14px; }
  .report-summary-change { color: var(--accent); font-weight: 600; }

  .js .report-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: #253d3899; opacity: 0; pointer-events: none; transition: opacity .36s cubic-bezier(.16, 1, .3, 1); }
  .js.report-sheet-open .report-scrim { opacity: 1; pointer-events: auto; }
  .js .report-filters { position: fixed; z-index: 60; left: 0; right: 0; bottom: 0; max-height: 88dvh; margin: 0; padding: 20px 16px max(24px, env(safe-area-inset-bottom)); overflow-y: auto; border-radius: 16px 16px 0 0; background: var(--paper); box-shadow: var(--shadow-modal); transform: translateY(100%); visibility: hidden; transition: transform .36s cubic-bezier(.16, 1, .3, 1), visibility 0s linear .36s; }
  .js.report-sheet-open .report-filters { transform: none; visibility: visible; transition-delay: 0s; }
  .js .report-sheet-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 20px; }
  .report-sheet-head h2 { margin: 0; font-size: 19px; }
  .report-sheet-head .report-reset { min-height: 36px; padding: 0 4px; }
  .report-sheet-grip { position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; border-radius: 2px; background: var(--grey-300); transform: translateX(-50%); }
  .js .report-filter-row { flex-direction: column; align-items: stretch; gap: 20px; }
  .js .report-filter-row .report-reset { display: none; }
  .report-filter-row > .ui-field:first-child, .report-period, .report-history { flex: none; max-width: none; margin: 0; width: 100%; }
  .report-custom { flex-direction: column; }
  .js .report-sheet-foot { display: flex; flex-direction: column; gap: 12px; margin: 20px 0 0; }
  .js .report-switch-sheet { display: inline-flex !important; flex-direction: row-reverse; justify-content: space-between; width: 100%; }
  .js .report-switch-main { display: none !important; }
  .report-sheet-foot .button { width: 100%; }
  .report-sheet-foot .ui-help { text-align: center; }
  html.report-sheet-open { overflow: hidden; }

  .report-results { display: flex; flex-direction: column; padding: 16px; }
  .report-results > * { order: 1; }
  .js .report-scope { display: none; }
  .report-card-head { display: contents; }
  .report-card-title { flex: none; order: 1; }
  .report-card-tools { order: 3; margin-top: 16px; }
  .report-card-tools .report-csv { width: 100%; }
  .report-body { order: 2; }
  .report-foot { order: 4; margin: 16px -16px -16px; padding: 14px 16px; }
  .report-progress { order: 0; }
  .report-figures { display: block; margin-top: 16px; }
  .report-figures .ui-figure:not(.is-emphasis), .report-op { display: none; }
  .report-figures .ui-figure { padding: 16px; }
  .report-figures .ui-figure-detail { display: block; }
  .report-sheet { margin: 16px -16px 0; }
  .report-sheet-table :is(th, td) { padding-inline: 16px; }
  .report-corrections .report-section { margin: 16px -16px 0; }
  .report-corrections .report-section-head { padding: 12px 16px; }
  .report-corrections .financial-report-table :is(th, td) { padding: 12px 16px; }
  .report-more-grid { grid-template-columns: 1fr; padding: 4px 14px 16px; }
}
