/* WP50 P4: reports (hub, runner, grid) and the System / admin pages. Values come from tokens.css.
   Selectors are scoped (#report-grid, .report-*, .kit-report-*, .sys-*) so the shared list and form styles stay untouched. */

/* ---------- Reports hub: area tabs and a searchable launcher ---------- */
.report-hub-layout { display: grid; grid-template-columns: 200px minmax(0, 820px); gap: var(--sp-8); align-items: start; }
.report-areas { position: sticky; top: calc(var(--h-topbar) + var(--sp-4)); display: flex; flex-direction: column; gap: 1px; }
.report-area {
  display: flex; align-items: center; min-height: 30px; padding: 0 10px;
  border-radius: var(--r-ctrl); color: var(--text-secondary); font-size: var(--fs-body); font-weight: 500;
  text-decoration: none; white-space: nowrap;
  transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.report-area:hover { color: var(--text); background: var(--surface-hover); }
.report-area[aria-current="page"] { background: var(--surface-selected); color: var(--accent-text); font-weight: 600; }

.report-hub { max-width: none; margin: 0; overflow: visible; }
.report-hub-search {
  position: relative; display: flex; align-items: center; gap: var(--sp-3); margin: 0 0 var(--sp-3);
}
.report-hub-search > .icon { position: absolute; left: 11px; color: var(--text-muted); pointer-events: none; }
.report-hub-search input {
  flex: 1; min-width: 0; height: 36px; padding: 0 var(--sp-3) 0 34px;
  border: 1px solid var(--border-input); border-radius: var(--r-ctrl);
  background: var(--surface); color: var(--text); font: 450 var(--fs-md) / 1 var(--font-ui);
}
.report-hub-search input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.report-hub-count { flex: none; color: var(--text-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

.report-hub table.kit-list {
  width: 100%; min-width: 0; margin: 0; border-collapse: separate; border-spacing: 0;
  border: 1px solid var(--border); border-radius: var(--r-panel); overflow: hidden;
  background: var(--surface); box-shadow: none;
}
.report-hub table.kit-list thead th {
  height: auto; padding: 8px var(--sp-4); border: 0; border-bottom: 1px solid var(--border);
  background: var(--surface-sunken); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em; text-transform: none;
}
.report-hub table.kit-list thead th:last-child, .report-hub table.kit-list tbody td:last-child { width: 1%; text-align: right; }
.report-hub table.kit-list tbody tr { border: 0; cursor: pointer; }
.report-hub table.kit-list tbody td {
  height: 40px; padding: 0 var(--sp-4); border: 0; border-bottom: 1px solid var(--border); background: transparent;
}
.report-hub table.kit-list tbody tr:last-child td { border-bottom: 0; }
.report-hub table.kit-list tbody tr:hover { background: var(--surface-hover); }
.report-hub table.kit-list tbody tr:focus { outline: none; background: var(--surface-selected); box-shadow: inset 2px 0 0 var(--accent); }
.report-hub table.kit-list tbody td a {
  display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 500; text-decoration: none;
}
.report-hub table.kit-list tbody td a .icon { width: 16px; height: 16px; color: var(--text-muted); }
.report-hub table.kit-list tbody tr:focus td a, .report-hub table.kit-list tbody tr:focus td a .icon { color: var(--accent-text); }
.report-hub table.kit-list tbody td:last-child { color: var(--text-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

/* empty states (hub search, report grid) */
.report-empty {
  display: grid; justify-items: center; gap: var(--sp-2); padding: var(--sp-10) var(--sp-6);
  border: 1px dashed var(--border-strong); border-radius: var(--r-panel); color: var(--text-secondary); text-align: center;
}
.report-empty p { margin: 0; }
.report-empty > .icon, .kit-report-empty .icon { color: var(--text-faint); }

/* ---------- Report runner: one-line filter toolbar (the lists pattern, docs/design/tables.md) ---------- */
#report-form.report-toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-5) var(--sp-3);   /* row gap leaves room for the AD date under a Miti box */
  margin: 0 0 var(--sp-5); padding: 0; border: 0; background: none; box-shadow: none;
}
#report-form:not(.is-open) .list-more { display: none; }
#report-form .list-more { display: contents; }
#report-form label {
  position: relative; display: flex; flex-direction: column; gap: 4px; margin: 0;
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-secondary); text-transform: none; letter-spacing: 0;
}
#report-form .miti-ad { position: absolute; top: 100%; left: 0; margin-top: 2px; font-size: var(--fs-xs); font-weight: 450; color: var(--text-muted); white-space: nowrap; }
#report-form :is(input:not([type=hidden]):not([type=checkbox]), select) {
  width: 160px; height: var(--h-control); padding: 0 10px; box-sizing: border-box;
  border: 1px solid var(--border-input); border-radius: var(--r-ctrl); background: var(--surface); color: var(--text);
  font: 450 var(--fs-body) / 1 var(--font-ui);
  transition: border-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
}
#report-form :is(input:not([type=hidden]), select):hover { border-color: var(--border-strong); }
#report-form :is(input, select):focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
#report-form .btn { height: var(--h-control); box-shadow: none; }
#report-form .btn-primary { padding: 0 14px; border-radius: var(--r-ctrl); }
#report-form .list-more-toggle[aria-expanded="true"], #report-form.is-open .list-more-toggle { color: var(--accent-text); }

/* results bar: active-filter chips on the left; Share, Print and Excel on the right */
.report-resultbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-2); }
.report-resultbar > .btn-sm { box-shadow: none; }
.report-resultbar > .btn-sm .icon { color: var(--text-muted); }
.report-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.report-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 6px 0 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); border-radius: var(--r-pill);
  background: var(--accent-subtle); color: var(--accent-text); font: 500 var(--fs-sm) / 1 var(--font-ui); cursor: pointer;
}
.report-chip span { color: var(--text-secondary); font-weight: 450; }
.report-chip strong { font-weight: 600; }
.report-chip .icon { width: 14px; height: 14px; opacity: 0.7; }
.report-chip:hover .icon { opacity: 1; }
.report-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Share: a quiet button in the results bar that opens a small panel */
.kit-report-share { position: relative; }
.kit-report-share > summary {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px;
  border-radius: var(--r-ctrl); color: var(--text-secondary); font: 550 var(--fs-sm) / 1 var(--font-ui); cursor: pointer; list-style: none;
}
.kit-report-share > summary::-webkit-details-marker { display: none; }
.kit-report-share > summary .icon { color: var(--text-muted); }
.kit-report-share > summary:hover, .kit-report-share[open] > summary { color: var(--text); background: var(--surface-hover); }
.kit-report-share form {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: var(--z-popover); width: min(360px, calc(100vw - 32px));
  display: grid; gap: var(--sp-3); padding: var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface-raised); box-shadow: var(--shadow-float);
}
.kit-report-share label { display: flex; flex-direction: column; gap: 5px; font-size: var(--fs-sm); font-weight: 500; color: var(--text-secondary); }
.kit-report-share input, .kit-report-share textarea {
  width: 100%; min-height: 30px; padding: 5px var(--sp-2); border: 1px solid var(--border-input); border-radius: var(--r-ctrl);
  background: var(--surface); color: var(--text); font: 450 var(--fs-body) / 1.4 var(--font-ui); resize: vertical;
}
.kit-report-share input:focus, .kit-report-share textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.kit-report-share .btn { height: 30px; }
#share-result p { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); }

/* ---------- Report grid ---------- */
.kit-report-scope { margin: 0 0 var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kit-report-scroll {
  max-height: calc(100dvh - 260px); min-height: 120px; overflow: auto; margin: 0 0 var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface);
}
#report-grid [data-report-grid] {
  width: 100%; min-width: 0; margin: 0; border: 0; border-radius: 0; box-shadow: none; overflow: visible;
  border-collapse: separate; border-spacing: 0; background: transparent;
  font-size: var(--fs-grid); font-variant-numeric: tabular-nums;
}
#report-grid [data-report-grid] th, #report-grid [data-report-grid] td { white-space: nowrap; }
#report-grid [data-report-grid] thead th {
  position: sticky; top: 0; z-index: 2; height: 30px; padding: 0 var(--sp-3);
  background: var(--surface-sunken); color: var(--text-secondary); border: 0; border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm); font-weight: 600; letter-spacing: 0; text-transform: none; text-align: left;
}
#report-grid [data-report-grid] thead th.num { text-align: right; }
#report-grid [data-report-grid] thead tr:nth-child(2) th { top: 30px; }
#report-grid [data-report-grid] thead td { position: sticky; top: 0; z-index: 2; background: var(--surface-sunken); border-bottom: 1px solid var(--border); }
#report-grid [data-report-grid] thead th[data-band] {
  text-align: center; color: var(--text-muted); font-size: var(--fs-xs); border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
#report-grid [data-report-grid] tbody tr { border: 0; cursor: default; }
#report-grid [data-report-grid] tbody tr[data-href]:not([data-href=""]) { cursor: pointer; }
#report-grid [data-report-grid] tbody td {
  height: var(--h-row); padding: 0 var(--sp-3); border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text);
}
#report-grid [data-report-grid] td.num { text-align: right; }
#report-grid [data-report-grid] tbody tr:hover td { background: var(--surface-hover); }
#report-grid [data-report-grid] tbody tr:focus { outline: none; }
#report-grid [data-report-grid] tbody tr:focus td { background: var(--surface-selected); }
#report-grid [data-report-grid] tbody tr:focus td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
#report-grid [data-report-grid] tbody td a { color: var(--accent-text); text-decoration: none; }
#report-grid [data-report-grid] tbody td a:hover { text-decoration: underline; }
/* row styles from the report engine (RowStyle) */
#report-grid [data-report-grid] tr.row-group td { font-weight: 650; background: var(--surface-sunken); }
#report-grid [data-report-grid] tr.row-opening td, #report-grid [data-report-grid] tr.row-closing td { font-weight: 600; color: var(--text-secondary); }
#report-grid [data-report-grid] tr.row-subtotal td { font-weight: 650; border-top: 1px solid var(--border-strong); }
/* totals: pinned to the bottom of the scroll box */
#report-grid [data-report-grid] tfoot td {
  position: sticky; bottom: 0; z-index: 1; height: 32px; padding: 0 var(--sp-3);
  background: var(--surface-raised); border: 0; border-top: 1px solid var(--border-strong);
  color: var(--text); font-weight: 650; text-align: right;
}
#report-grid [data-report-grid] tfoot td:first-child { text-align: left; }
#report-grid .kit-report-empty {
  height: auto !important; padding: var(--sp-10) 0 !important; text-align: center; color: var(--text-secondary); white-space: normal !important;
}
#report-grid .kit-report-empty .icon { display: block; margin: 0 auto var(--sp-2); }
/* the message stays in view on a grid wider than the screen */
#report-grid .report-empty-msg { position: sticky; left: 0; width: min(100%, calc(100vw - var(--w-sidebar) - 2 * var(--sp-8))); }
.sidebar-collapsed #report-grid .report-empty-msg { width: min(100%, calc(100vw - var(--w-rail) - 2 * var(--sp-8))); }
#report-grid tbody tr:hover .kit-report-empty { background: transparent; }

.kit-report-pager { display: flex; align-items: center; gap: var(--sp-3); margin: 0 0 var(--sp-3); font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.kit-report-pager button {
  height: 30px; padding: 0 var(--sp-3); border: 1px solid var(--border-strong); border-radius: var(--r-ctrl);
  background: var(--surface); color: var(--text); font: 550 var(--fs-body) / 1 var(--font-ui); box-shadow: none; cursor: pointer;
}
.kit-report-pager button:hover:not(:disabled) { background: var(--surface-hover); }
.kit-report-pager button:disabled { color: var(--text-faint); cursor: default; }
.kit-report-pager button { --spin: var(--text-muted); }
#report-grid > .kit-note { margin: 0 0 var(--sp-1); color: var(--text-muted); font-size: var(--fs-sm); }
#report-grid > .kit-error {
  margin: 0; padding: var(--sp-3) var(--sp-4); border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
  border-radius: var(--r-panel); background: var(--danger-subtle); color: var(--danger); font-weight: 500;
}

/* loading: skeleton rows the first time, the old grid dimmed after that (htmx marks the form .htmx-request) */
#report-form.htmx-request ~ #report-grid > * { opacity: 0.5; transition: opacity var(--dur-2) var(--ease-out); }
#report-form.htmx-request ~ #report-grid:empty::before {
  content: ""; display: block; height: 300px; border: 1px solid var(--border); border-radius: var(--r-panel); background-color: var(--surface);
  background-image:
    linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 75%, transparent), transparent),
    linear-gradient(var(--surface-sunken) 0 30px, var(--border) 30px 31px, transparent 31px),
    repeating-linear-gradient(transparent 0 9px, var(--border) 9px 17px, transparent 17px 27px),
    repeating-linear-gradient(transparent 0 9px, var(--border) 9px 17px, transparent 17px 27px),
    repeating-linear-gradient(transparent 0 26px, var(--border) 26px 27px);
  background-size: 30% 100%, 100% 100%, 38% 100%, 14% 100%, 100% 100%;
  background-position: -40% 0, 0 0, 12px 31px, calc(100% - 12px) 31px, 0 31px;
  background-repeat: no-repeat;
  animation: report-shimmer 1.2s linear infinite;
}
@keyframes report-shimmer { to { background-position: 140% 0, 0 0, 12px 31px, calc(100% - 12px) 31px, 0 31px; } }
@media (prefers-reduced-motion: reduce) { #report-form.htmx-request ~ #report-grid:empty::before { animation: none; } }

@media (max-width: 900px) {
  .report-hub-layout { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
  .report-areas {
    position: static; flex-direction: row; gap: var(--sp-1); overflow-x: auto; margin: 0 calc(-1 * var(--sp-4)); padding: 0 var(--sp-4) 2px;
    scrollbar-width: none;
  }
  .report-area { flex: none; min-height: 30px; border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface); }
  .report-area[aria-current="page"] { border-color: transparent; }
  #report-form label { flex: 1 1 140px; }
  #report-form :is(input:not([type=hidden]):not([type=checkbox]), select) { width: 100%; }
  #report-grid .report-empty-msg { width: calc(100vw - 2 * var(--sp-4)); }
  .kit-report-share form { grid-template-columns: 1fr; }
  .kit-report-scroll { max-height: none; }
  #report-grid [data-report-grid] tfoot td { position: static; }
}
@media (max-width: 480px) {
  #report-form [data-kit-save] { flex: 1 0 100%; }
  .report-chips { flex: 1 0 100%; }
}

/* ---------- System / admin pages: panels, notes, status and results (form fields belong to ui-forms.css) ---------- */
/* kit.css widens every direct child of main to 1440px and centres it; System panels stay at a readable width, left-aligned */
#main > :is(.sys-panel, .sys-callout) { max-width: 880px; margin: 0 0 var(--sp-4); }
.sys-panel {
  max-width: 880px; margin: 0 0 var(--sp-4); padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface);
}
.sys-prose { color: var(--text-secondary); line-height: 1.6; }
.sys-prose p { margin: 0 0 var(--sp-3); }
.sys-prose ul { margin: 0; padding-left: var(--sp-5); }
.sys-prose li + li { margin-top: var(--sp-1); }
.sys-prose strong, .sys-prose em { color: var(--text); }
.sys-callout {
  display: flex; align-items: flex-start; gap: var(--sp-2); max-width: 880px; margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4);
  border: 1px solid color-mix(in srgb, var(--warning) 30%, var(--border)); border-radius: var(--r-panel);
  background: var(--warning-subtle); color: var(--text);
}
.sys-callout > .icon { margin-top: 2px; color: var(--warning); }
section.sys-callout { display: block; }
.sys-callout code { font-size: var(--fs-sm); }

/* status pills, summaries, empty state */
.sys-status {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: var(--r-pill);
  font-size: var(--fs-sm); font-weight: 550; white-space: nowrap;
}
.sys-status .icon { width: 14px; height: 14px; }
.sys-status.is-ok { background: var(--success-subtle); color: var(--success); }
.sys-status.is-bad { background: var(--danger-subtle); color: var(--danger); }
.sys-status.is-off { background: var(--surface-sunken); color: var(--text-muted); }
.sys-summary {
  display: flex; align-items: center; gap: var(--sp-3); max-width: 880px; margin: var(--sp-4) 0; padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface);
}
.sys-summary p { margin: 0; }
.sys-summary p + p { color: var(--text-muted); font-size: var(--fs-sm); }
.sys-summary.is-ok > .icon { color: var(--success); }
.sys-summary.is-bad > .icon { color: var(--danger); }
.sys-empty {
  display: grid; justify-items: center; gap: var(--sp-2); max-width: 880px; margin: var(--sp-4) 0; padding: var(--sp-10) var(--sp-6);
  border: 1px dashed var(--border-strong); border-radius: var(--r-panel); color: var(--text-secondary); text-align: center;
}
.sys-empty p { margin: 0; }
.sys-empty > .icon { color: var(--text-faint); }

/* integrity results */
.sys-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface); }
table.sys-table { width: 100%; border-collapse: collapse; font-size: var(--fs-grid); }
table.sys-table th {
  height: 32px; padding: 0 var(--sp-3); background: var(--surface-sunken); border-bottom: 1px solid var(--border);
  color: var(--text-secondary); font-size: var(--fs-sm); font-weight: 600; text-align: left; white-space: nowrap;
}
table.sys-table th.num, table.sys-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.sys-table td { padding: 6px var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: top; }
table.sys-table tbody tr:last-child td { border-bottom: 0; }
table.sys-table tbody tr:hover td { background: var(--surface-hover); }
table.sys-table tbody tr:focus { outline: none; }
table.sys-table tbody tr:focus td { background: var(--surface-selected); }
table.sys-table summary { cursor: pointer; color: var(--text-secondary); }
table.sys-table details[open] summary { color: var(--text); margin-bottom: 4px; }
table.sys-table details div { color: var(--text-secondary); font-size: var(--fs-sm); }

/* migrator: run status, steps, log */
.sys-run > p { margin: 0 0 var(--sp-2); color: var(--text-secondary); }
.sys-run > p strong { color: var(--text); }
ol.sys-steps { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin: var(--sp-3) 0; padding: 0; list-style: none; }
ol.sys-steps li {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--sp-3) 0 var(--sp-2);
  border: 1px solid var(--border); border-radius: var(--r-pill); color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500;
}
ol.sys-steps li.is-done { color: var(--success); background: var(--success-subtle); border-color: transparent; }
ol.sys-steps li.is-running { color: var(--accent-text); background: var(--accent-subtle); border-color: transparent; }
ol.sys-steps li.is-failed { color: var(--danger); background: var(--danger-subtle); border-color: transparent; }
.sys-step-dot { width: 8px; height: 8px; margin: 0 3px; border-radius: 50%; border: 1.5px solid currentColor; }
.sys-run details > summary { cursor: pointer; color: var(--text-secondary); font-weight: 500; }
pre.sys-log {
  max-height: 320px; overflow: auto; margin: var(--sp-2) 0 0; padding: var(--sp-3);
  border-radius: var(--r-ctrl); background: var(--surface-sunken); color: var(--text-secondary);
  font: 450 var(--fs-sm) / 1.55 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap;
}

@media (max-width: 640px) { .sys-panel { padding-left: var(--sp-4); padding-right: var(--sp-4); } }
