/* Quima Audit Engine. Uses site.css tokens and components (panel, btn, data-table, notice).
   Mobile contract: fields 16px+, targets 44px+, no horizontal page scroll at 320px. */
.auditor { display: grid; gap: 20px; min-width: 0; }
.auditor .panel { min-width: 0; padding: 24px; }
.aud-local { display: flex; width: fit-content; max-width: 100%; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.aud-local span { min-width: 0; overflow-wrap: anywhere; }
.aud-local svg { flex: none; }
[data-auditor-guide] .table-wrap { overflow-x: auto; max-width: 100%; }
.aud-status { margin: 0; overflow-wrap: anywhere; color: var(--muted); }
.aud-status[data-state=error] { color: var(--err); font-weight: 600; }
.aud-status[data-state=ok] { color: var(--ok); }

/* Chooser */
.aud-chooser-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.aud-chooser-head h2 { margin: 0; }
.aud-search { max-width: 420px; margin-block: 16px; }
.aud-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 16px; }
.aud-card { display: flex; flex-direction: column; gap: 8px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.aud-card h3 { margin: 0; font-size: 1.1rem; }
.aud-card p { margin: 0; overflow-wrap: anywhere; }
.aud-card .btn { margin-top: auto; align-self: flex-start; }
.aud-card.is-active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-line); }
.aud-card[hidden] { display: none; }

/* Workspace */
.aud-head h2 { margin: 4px 0 8px; }
.aud-bar-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-block: 12px; }
.aud-name { flex: 1 1 240px; }
.aud-mode { display: inline-flex; }
.aud-mode .segment { min-height: 44px; min-width: 96px; padding: 6px 14px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font: inherit; cursor: pointer; touch-action: manipulation; }
.aud-mode .segment:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.aud-mode .segment:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 0; }
.aud-mode .segment[aria-checked=true] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.aud-mode .segment:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.aud-save { color: var(--muted); font-size: .95rem; min-height: 44px; display: inline-flex; align-items: center; }
.aud-save[data-state=ok] { color: var(--ok); }
.aud-save[data-state=error] { color: var(--err); font-weight: 600; }
.auditor details { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px 12px; margin-block: 12px; background: var(--surface); }
.auditor summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; overflow-wrap: anywhere; }
.auditor summary:focus-visible, .aud-step:focus-visible, .aud-drop:focus-within { outline: 3px solid var(--brand); outline-offset: 2px; }

.aud-steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 16px 0; overflow-x: auto; scrollbar-width: thin; }
.aud-steps li { flex: 1 0 auto; }
.aud-step { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink-2); font: inherit; cursor: pointer; touch-action: manipulation; white-space: nowrap; }
.aud-step[aria-current=step] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; }
.aud-step:disabled { opacity: .5; cursor: not-allowed; }
.aud-step .step-number { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--line); font-size: .85rem; }
.aud-step[aria-current=step] .step-number { background: var(--brand); color: #fff; }

/* Fields (FormRenderer) */
.aud-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px 16px; min-width: 0; }
.aud-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-block: 6px; }
.aud-field.aud-wide { grid-column: 1 / -1; }
.aud-field input:not([type=checkbox]):not([type=radio]):not([type=file]), .aud-field select, .aud-field textarea,
.aud-filters input, .aud-filters select, .aud-score input, .aud-dialog input {
    width: 100%; min-width: 0; max-width: 100%; min-height: 44px; font: inherit; font-size: 1rem; padding: 8px 10px;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.aud-field textarea { min-height: 88px; resize: vertical; }
.aud-field [aria-invalid=true], .aud-mapping [aria-invalid=true] { border-color: var(--err); box-shadow: 0 0 0 1px var(--err); }
.aud-check, .aud-choice { flex-direction: row; align-items: center; gap: 10px; min-height: 44px; display: flex; }
.aud-check input, .aud-choice input { width: 24px; height: 24px; flex: none; margin: 0; }
.aud-choices { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.aud-static { grid-column: 1 / -1; background: var(--brand-soft); padding: 10px 12px; border-radius: var(--radius-sm); }
.aud-photo { display: block; max-width: min(100%, 240px); max-height: 180px; object-fit: contain; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.aud-photo[hidden] { display: none; }
.aud-file { position: relative; display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; }
.aud-scores { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 8px 12px; }
.aud-score { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.aud-list { margin-block: 16px; min-width: 0; }
.aud-list-title { margin-bottom: 4px; }
.aud-section { margin: 20px 0 6px; color: var(--brand-strong); font-size: 1rem; }
.aud-item { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin: 0 0 12px; min-width: 0; background: var(--surface); }
.aud-item legend { font-weight: 600; padding: 0 6px; max-width: 100%; overflow-wrap: anywhere; }
.aud-item-actions, .aud-list-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* Data sources */
.aud-datasets { display: grid; gap: 16px; margin-block: 16px; }
.aud-dataset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; background: var(--surface); }
.aud-dataset h4 { margin: 0 0 6px; overflow-wrap: anywhere; }
.aud-drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 96px; padding: 16px; margin-top: 12px; border: 2px dashed var(--line-strong); border-radius: var(--radius); text-align: center; cursor: pointer; background: var(--bg); touch-action: manipulation; }
.aud-drop.is-over { border-color: var(--brand); background: var(--brand-soft); }
.aud-drop-title { font-weight: 700; color: var(--brand-strong); }
.aud-dataset .record-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-block: 8px; border-bottom: 1px solid var(--line); }
.aud-dataset .record-name { margin: 0; overflow-wrap: anywhere; }
.aud-go { margin-top: 20px; }
.auditor .button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.auditor .table-wrap { overflow-x: auto; max-width: 100%; margin-block: 12px; }
.auditor .data-table td, .auditor .data-table th { overflow-wrap: anywhere; }
.auditor .data-table td.num { text-align: right; white-space: nowrap; }
.auditor .data-table .is-invalid { background: var(--err-soft); color: var(--err); }
.aud-mapping { background: var(--bg); padding: 12px; border-radius: var(--radius-sm); }

/* Results */
.aud-results { min-width: 0; }
.aud-results progress, .aud-pane > progress { width: 100%; height: 12px; }
.aud-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 12px; margin: 16px 0; }
.aud-kpi { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: var(--surface); min-width: 0; }
.aud-kpi dt { font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.aud-kpi dd { margin: 4px 0 0; font-size: 1.25rem; font-weight: 700; overflow-wrap: anywhere; }
.aud-chart { margin: 20px 0; min-width: 0; }
.aud-chart figcaption { font-weight: 700; margin-bottom: 8px; }
.aud-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.aud-bars li { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; align-items: center; gap: 8px; min-width: 0; }
.aud-bar-label { overflow-wrap: anywhere; font-size: .95rem; }
.aud-bar-track { position: relative; height: 14px; background: var(--bg); border-radius: 7px; overflow: hidden; border: 1px solid var(--line); }
.aud-bar { position: absolute; inset: 0 auto 0 0; background: var(--brand); border-radius: 7px; }
.aud-bar-compare { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--ink); }
.aud-bar-value { font-variant-numeric: tabular-nums; font-size: .9rem; white-space: nowrap; }
.aud-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 8px 12px; align-items: end; margin-block: 12px; }
.aud-finding { border: 1px solid var(--line); border-left-width: 6px; border-radius: var(--radius-sm); margin: 0 0 10px; padding: 0 12px; background: var(--surface); }
.aud-finding.sev-high { border-left-color: var(--err); }
.aud-finding.sev-medium { border-left-color: var(--warn); }
.aud-finding.sev-low { border-left-color: var(--brand); }
.aud-finding.sev-info { border-left-color: var(--line-strong); }
.aud-finding summary { display: flex; flex-wrap: wrap; gap: 6px 10px; padding-block: 8px; font-weight: 400; }
.aud-finding-title { flex: 1 1 200px; font-weight: 600; overflow-wrap: anywhere; }
.aud-sev, .aud-status { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: .85rem; background: var(--bg); border: 1px solid var(--line); }
.sev-high .aud-sev { background: var(--err-soft); color: var(--err); }
.sev-medium .aud-sev { background: var(--warn-soft); color: var(--warn); }
.aud-status.st-confirmed { background: var(--err-soft); color: var(--err); }
.aud-status.st-dismissed { background: var(--ok-soft); color: var(--ok); }
.aud-finding-body { padding-bottom: 12px; min-width: 0; }
.aud-facts { display: grid; gap: 6px; margin: 8px 0; }
.aud-facts > div { display: grid; grid-template-columns: minmax(110px, 28%) 1fr; gap: 8px; }
.aud-facts dt { color: var(--muted); }
.aud-facts dd { margin: 0; overflow-wrap: anywhere; }
.aud-review { border: 0; padding: 0; margin: 12px 0 4px; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.aud-review legend { font-weight: 600; margin-bottom: 4px; }
.aud-limit { font-style: italic; }
.aud-pager { align-items: center; }
.aud-notes { margin-top: 24px; padding: 16px; border-radius: var(--radius-sm); background: var(--bg); }
.aud-notes p { overflow-wrap: anywhere; }
.aud-actions { margin-top: 24px; }
.aud-export { margin-block: 16px; }
.aud-history .record-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding-block: 12px; border-bottom: 1px solid var(--line); }
.aud-history .record-info { min-width: 0; flex: 1 1 220px; }
.aud-history .record-name, .aud-history .record-meta { margin: 0; overflow-wrap: anywhere; }
.aud-history .records-list { list-style: none; padding: 0; margin: 0; }
.aud-dialog { max-width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: auto; }
.aud-print { display: none; }

@media (max-width: 600px) {
    .auditor .panel { padding: 16px; }
    .auditor .button-row .btn, .aud-go .btn { flex: 1 1 160px; white-space: normal; }
    .aud-bars li { grid-template-columns: 1fr auto; }
    .aud-bars .aud-bar-track { grid-column: 1 / -1; grid-row: 2; }
    .aud-facts > div { grid-template-columns: 1fr; gap: 0; }
    .aud-step { padding: 6px 10px; }
}
@media (hover: hover) {
    .aud-step:hover:not(:disabled) { border-color: var(--brand); }
    .aud-drop:hover { border-color: var(--brand); }
    .aud-card:hover { border-color: var(--brand-line); }
}

/* Print: only the generated report. */
@media print {
    body.aud-printing > *:not(.site-main):not(main), body.aud-printing .site-header, body.aud-printing .site-footer, body.aud-printing .page-head,
    body.aud-printing .auditor > :not([data-print]), body.aud-printing .ad-slot, body.aud-printing [data-auditor-guide] { display: none !important; }
    body.aud-printing .aud-print { display: block; color: #000; }
    body:not(.aud-printing) .auditor, body:not(.aud-printing) [data-auditor-guide] { display: none; }
    .aud-print h1 { font-size: 18pt; } .aud-print h2 { font-size: 13pt; margin-top: 14pt; break-after: avoid; }
    .aud-print table { width: 100%; border-collapse: collapse; font-size: 8.5pt; } .aud-print th, .aud-print td { border: 1px solid #999; padding: 3pt; vertical-align: top; }
    .aud-print tr { break-inside: avoid; }
    .aud-print-meta { display: grid; grid-template-columns: 30% 1fr; gap: 2pt 8pt; } .aud-print-meta dd { margin: 0; }
    .aud-print .aud-bars li { grid-template-columns: 35% 1fr auto; } .aud-print .aud-bar { background: #333; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
