/* BuildProof - app-specific styles on top of the shared portal.css (linked first by index.html).
   The shared sheet is written against --navy / --amber tokens; data-theme="buildproof" on <html> points
   them at its own identity (deep teal + safety orange) so every shared component picks the brand up unchanged.
   The shared sheet is now _content/TechnoPulse.Ui/css/suite.css, which imports portal.css into the
   cascade layer "legacy" (as css/legacy/portal.legacy.css). Every rule below sits in that same layer,
   after it, so the order and specificity are as before; new rules go in @layer modules, never
   outside a layer (an unlayered rule beats every layer). */

@layer legacy {
/* BuildProof's identity no longer re-points the tokens on :root: index.html sets data-theme="buildproof",
   and the shared aliases (--navy #0E4D64, --navy-light #186A87, --amber #F26B1D, --amber-dark #A8470B
   (text-only orange: 5.5:1 on the page and >= 4.6:1 on every peach pill / alert; the old #C4520F was ~3:1),
   --bg #F4F7F7, the teal --shadow and, in the dark scheme, --bg #101719, --surface #182226,
   --surface-2 #1F2C31, --amber-dark #FF9F66) resolve to the buildproof theme in TechnoPulse.Ui
   css/tokens/themes.css. The severity scale is the risk scale. */
:where(:root, [data-theme], [data-accent], [data-scheme]) {
    --sev-low: var(--color-risk-low);
    --sev-medium: var(--color-risk-medium);
    --sev-high: var(--color-risk-high);
    --sev-critical: var(--color-risk-very-high);
}

/* Dark scheme (was @media (prefers-color-scheme: dark); :where() keeps each selector's specificity).
   The verdict pills' status text needs no dark rule any more: --success-text and --danger-text follow the
   scheme (DS-F11; the dark pass rule came before the light one and never applied, 2.1:1). */

/* ---- new report form ---------------------------------------------------------------------- */
.trade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
@media (min-width: 640px) { .trade-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---- photo grid ---------------------------------------------------------------------------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; }
.photo-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.photo-card.selected { outline: 2px solid var(--amber); }
.photo-thumb { aspect-ratio: 4 / 3; width: 100%; object-fit: cover; background: var(--surface-2); display: block; }
.photo-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 1.5rem; }
.photo-card-body { padding: 0.45rem 0.55rem; display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; }
.photo-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
/* A 44 px tap target (the touch floor) around a smaller visible disc in the corner. */
.photo-remove { position: absolute; top: 0; right: 0; z-index: 1; isolation: isolate; width: 44px; height: 44px; padding: 6px 6px 8px 8px; border: none; background: transparent; color: #fff; font-size: 0.9rem; line-height: 30px; text-align: center; cursor: pointer; }
.photo-remove::before { content: ""; position: absolute; top: 6px; right: 6px; z-index: -1; width: 30px; height: 30px; border-radius: 50%; background: rgba(0, 0, 0, 0.6); }
.photo-remove:focus-visible { outline: 3px solid var(--amber); outline-offset: -3px; border-radius: 50%; }
.photo-remove:disabled { opacity: 0.4; cursor: default; }

/* ---- upload progress ----------------------------------------------------------------------- */
.upload-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.upload-actions input[type="file"] { display: none; }
/* The photo buttons were labels, and inside a form field (a question's photo request) ".field label" gave
   them its 0.9rem; they keep that size as buttons (DS-F10 changes no pixels). */
.field .upload-actions .btn { font-size: 0.9rem; }
.upload-progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.upload-progress > span { display: block; height: 100%; background: var(--amber); transition: width 0.2s ease; }
.upload-progress.done > span { background: var(--success); }
.upload-progress.failed > span { background: var(--danger); }

/* ---- verdicts & findings ------------------------------------------------------------------- */
.verdict-pill { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; }
.verdict-pill.pass { background: color-mix(in srgb, var(--success) 16%, var(--surface)); color: var(--success-text); }
.verdict-pill.issues { background: color-mix(in srgb, var(--sev-high) 16%, var(--surface)); color: var(--amber-dark); }
.verdict-pill.needs-info { background: color-mix(in srgb, var(--sev-medium) 22%, var(--surface)); color: var(--amber-dark); }
.verdict-pill.failed { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger-text, var(--danger)); }
.verdict-pill.pending, .verdict-pill.analysing { background: var(--surface-2); color: var(--text-secondary); }
/* A status, not a button: hug the text instead of stretching across the card. */
.photo-card-body .verdict-pill, .result-title .verdict-pill { align-self: flex-start; }

.result-card { border-left: 4px solid var(--border); }
.result-card.pass { border-left-color: var(--success); }
.result-card.issues { border-left-color: var(--sev-high); }
.result-card.needs-info { border-left-color: var(--sev-medium); }
.result-card.failed { border-left-color: var(--danger); }
.result-head { display: flex; gap: 0.75rem; align-items: flex-start; }
.result-head img { width: 96px; height: 72px; object-fit: contain; border-radius: var(--radius-sm); background: var(--surface-2); flex: none; }
.result-head .result-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.result-head h3 { margin: 0; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 640px) { .result-head img { width: 160px; height: 120px; } }
/* On a phone, a photo with something to decide is shown big enough to judge the finding; passes stay thumbnails. */
@media (max-width: 639px) {
    .result-card:not(.pass) .result-head { flex-direction: column; }
    .result-card:not(.pass) .result-head > a { display: block; width: 100%; }
    .result-card:not(.pass) .result-head img { width: 100%; height: auto; aspect-ratio: 4 / 3; max-height: 55vh; }
    .result-card:not(.pass) .result-head h3 { white-space: normal; }
}

.finding-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.7rem 0.8rem; display: flex; flex-direction: column; gap: 0.4rem; background: var(--surface); }
.finding-card.decided { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
/* Still to decide: the one that needs attention stands out (decided ones are quieter). */
.finding-card.undecided { border-color: var(--amber); box-shadow: inset 4px 0 0 var(--amber); }
.finding-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.finding-head strong { flex: 1; min-width: 0; }
.sev { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; color: #fff; text-transform: uppercase; letter-spacing: 0.02em; }
.sev.low { background: var(--sev-low); }
.sev.medium { background: var(--sev-medium); color: #1A1E28; }
.sev.high { background: var(--sev-high); color: #1A1E28; } /* white on orange was 3:1 */
.sev.critical { background: var(--sev-critical); }
.finding-meta { font-size: 0.85rem; color: var(--text-secondary); display: flex; flex-direction: column; gap: 0.15rem; }
.finding-meta span strong { color: var(--text); font-weight: 600; }
.finding-note { position: relative; }
.finding-note textarea { width: 100%; min-height: 2.75rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border-strong, var(--border)); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; font-size: 1rem; line-height: 1.4; resize: vertical; box-sizing: border-box; }
/* One line until used: grows while focused or once it holds a note. */
.finding-note textarea:focus, .finding-note textarea:not(:placeholder-shown) { min-height: 4.5rem; }
.finding-note textarea:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; border-color: var(--amber); }
.finding-note .spinner { position: absolute; right: 0.6rem; bottom: 0.6rem; }

.decision-segment { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
.decision-segment button { min-height: 44px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.85rem; font-weight: 600; cursor: pointer; padding: 0.35rem 0.4rem; }
.decision-segment button:disabled { cursor: default; opacity: 0.75; }
.decision-segment button.fix.selected { background: var(--danger); border-color: var(--danger); color: #fff; }
.decision-segment button.accept.selected { background: var(--info); border-color: var(--info); color: #fff; }
.decision-segment button.dismiss.selected { background: var(--text-secondary); border-color: var(--text-secondary); color: #fff; }
/* Dark: the light grey fill gave white text 2.6:1; this rule sat above the light one and never applied (DS-F11). */
:where([data-scheme="dark"]) .decision-segment button.dismiss.selected { background: #5A6272; border-color: #5A6272; }

.question-box { border: 1px dashed var(--sev-medium); border-radius: var(--radius-sm); padding: 0.7rem 0.8rem; display: flex; flex-direction: column; gap: 0.5rem; background: color-mix(in srgb, var(--sev-medium) 8%, var(--surface)); }
.question-box textarea { width: 100%; min-height: 4.5rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border-strong, var(--border)); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: 1rem; line-height: 1.4; resize: vertical; box-sizing: border-box; }
.question-box textarea:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; border-color: var(--amber); }

/* ---- analyse / finalise action cards ------------------------------------------------------- */
.action-card { display: flex; flex-direction: column; gap: 0.6rem; }
.action-card .quote { font-size: 1.05rem; font-weight: 600; }
.summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 0.5rem; }
.summary-strip > div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 0.55rem 0.7rem; display: flex; flex-direction: column; }
.summary-strip strong { font-size: 1.25rem; }
.summary-strip small { color: var(--text-secondary); }

/* ---- rooms / areas ------------------------------------------------------------------------- */
.area-heading { margin: 0.5rem 0 0; font-size: 1rem; display: flex; align-items: center; gap: 0.4rem; color: var(--navy); }
:where([data-scheme="dark"]) .area-heading { color: var(--amber); }
.area-heading:first-child { margin-top: 0; }
.photo-area { width: 100%; min-height: 44px; font: inherit; font-size: 16px; padding: 0.2rem 0.4rem; border: 1px solid var(--border-strong, var(--border)); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); }
.photo-area-new { display: flex; gap: 0.3rem; align-items: center; }
.photo-area-new input { flex: 1; min-width: 0; width: 100%; min-height: 44px; font: inherit; font-size: 16px; padding: 0.2rem 0.4rem; border: 1px solid var(--border-strong, var(--border)); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); box-sizing: border-box; }
.photo-area-new .hstack { gap: 0.3rem; }

/* ---- observations (not defects) ------------------------------------------------------------ */
.observations { border-left: 3px solid var(--border); padding: 0.35rem 0.75rem; color: var(--text-secondary); font-size: 0.9rem; }
.observations strong { color: var(--text); font-weight: 600; }
.observations ul { margin: 0.25rem 0 0; padding-left: 1.1rem; }

/* ---- guided QA record ---------------------------------------------------------------------- */
/* Kind picker on /new: two compact options side by side; the chosen one is explained underneath. */
.kind-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.kind-option { display: flex; align-items: center; gap: 0.6rem; min-height: 64px; padding: 0.6rem 0.75rem; text-align: left; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong, var(--border)); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; }
.kind-option:hover:not(:disabled) { border-color: var(--amber); }
.kind-option.selected { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber); background: color-mix(in srgb, var(--amber) 7%, var(--surface)); }
.kind-option:disabled { opacity: 0.55; cursor: not-allowed; }
.kind-option:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.kind-icon { font-size: 1.5rem; flex: none; }
.kind-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.kind-text strong { font-size: 0.95rem; line-height: 1.25; }
.kind-text small { color: var(--text-secondary); font-size: 0.78rem; line-height: 1.3; }
.kind-explainer { margin: 0.5rem 0 1rem; }
@media (max-width: 359px) { .kind-picker { grid-template-columns: 1fr; } }
/* Evidence photos carry a caption instead of a verdict. */
.photo-caption { width: 100%; min-height: 44px; font: inherit; font-size: 16px; padding: 0.2rem 0.4rem; border: 1px solid var(--border-strong, var(--border)); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); box-sizing: border-box; }
.photo-caption-text { color: var(--text); font-size: 0.8rem; }
.evidence-panel { margin-top: 0.75rem; }
/* A record section heading is a plain title here, not the collapse button it is on a RAMS. */
.record-section-title { cursor: default; }

/* ---- autosave, revisions ------------------------------------------------------------------- */
.result-thumb-placeholder { width: 96px; height: 72px; border-radius: var(--radius-sm); flex: none; }
.input-with-action { display: flex; gap: 0.5rem; }
.input-with-action input { flex: 1; min-width: 0; }
.revise-block { border-top: 1px solid var(--border); padding-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }

/* Revision banner (RevisionBanner.razor): text left, Discard right; stacks on a phone. */
.revision-banner { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 0.5rem 1rem; }
.revision-banner-main { flex: 1 1 320px; min-width: 0; }
.revision-banner-main p { margin: 0 0 0.35rem; }
.revision-banner-actions { flex: 0 1 auto; display: flex; flex-direction: column; gap: 0.35rem; }
.revision-banner .rule-indicator { margin: 0.25rem 0; gap: 0.25rem 0.75rem; }

/* Photo ✕ asks first: the confirmation covers the card until Remove / Keep. */
.photo-remove-confirm { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; justify-content: center; gap: 0.5rem; padding: 0.6rem; background: color-mix(in srgb, var(--surface) 94%, transparent); text-align: center; }
.photo-remove-confirm .hstack { justify-content: center; flex-wrap: wrap; }

/* Delete sits at the end of the page, away from everyday controls. */
.danger-zone { margin: 1.5rem 0 0.5rem; padding-top: 1rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; }
.new-report-hint { margin: 0; }

/* Desktop: keep reading lines and the decision buttons a comfortable width. */
@media (min-width: 900px) {
    .result-card > p, .observations, .finding-card > div:not(.decision-segment):not(.finding-head):not(.finding-note), .finding-note textarea { max-width: 75ch; }
    .decision-segment { max-width: 540px; }
    .signature-pad { max-width: 560px; }
}



/* ---- job details: summary first, "Change details" to edit ---------------------------------- */
.details-summary dd { overflow-wrap: anywhere; }
.details-summary .details-work { white-space: pre-line; }
.missing-value { color: var(--danger-text, var(--danger)); font-weight: 600; }
.trade-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.trade-chips li { padding: 0.2rem 0.6rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.85rem; font-weight: 600; }
.trade-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
/* A lock note with its Undo button: text, then the button underneath on a phone / beside it on a wide card. */
.details-card .lock-note { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; margin-top: 0.35rem; }
.details-card .lock-note > span { flex: 1 1 260px; }

/* ---- photo grid / result thumbnails open the viewer ---------------------------------------- */
.photo-open, .result-thumb-button { display: block; position: relative; padding: 0; border: 0; background: none; cursor: zoom-in; width: 100%; }
.photo-open:focus-visible, .result-thumb-button:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.result-thumb-button { width: auto; flex: none; border-radius: var(--radius-sm); }
.thumb-zoom { position: absolute; right: 4px; bottom: 4px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.8rem; }
@media (max-width: 639px) {
    .result-card:not(.pass) .result-head > .result-thumb-button { display: block; width: 100%; }
}

/* ---- results: needs attention, decided, passed (folded) ------------------------------------ */
.results-block { margin-bottom: 1rem; }
#photos-body[hidden] { display: none; }
.result-group { display: flex; flex-direction: column; gap: 0.75rem; }
.result-group-title { margin: 0.5rem 0 0; font-size: 1.05rem; }
.result-group-toggle { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; width: 100%; min-height: 48px; padding: 0.5rem 0.9rem; font: inherit; color: var(--text); text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; }
.result-group-toggle .result-group-title { margin: 0; }
.result-group-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h4.area-heading { font-size: 0.95rem; }
/* The finding the viewer's 1 / 2 / 3 keys decide. */
.finding-card.active { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- photo viewer --------------------------------------------------------------------------- */
body:has(.photo-viewer) { overflow: hidden; }
.photo-viewer {
    position: fixed; inset: 0; z-index: 55; display: grid;
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) minmax(0, auto);
    grid-template-areas: "head" "stage" "panel";
    background: var(--bg); outline: none;
}
.viewer-head {
    grid-area: head; display: flex; align-items: center; gap: 0.5rem;
    padding: calc(0.4rem + var(--safe-top)) max(0.5rem, env(safe-area-inset-right, 0px)) 0.4rem max(0.5rem, env(safe-area-inset-left, 0px));
    background: var(--navy); color: #fff;
}
.viewer-head .btn-ghost { color: #fff; }
.viewer-close { min-width: 44px; min-height: 44px; font-size: 1.1rem; }
.viewer-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.viewer-title h2 { margin: 0; font-size: 1rem; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-count { font-size: 0.8rem; opacity: 0.85; }
.viewer-nav { display: flex; gap: 0.35rem; }
.viewer-nav .btn { min-width: 44px; min-height: 44px; }
.viewer-nav-label { display: none; }
/* touch-action none: the stage's own swipe / pinch handling, never the browser's page zoom or scroll. */
.viewer-stage { grid-area: stage; position: relative; overflow: hidden; display: grid; place-items: center; background: #0B0F12; touch-action: none; min-height: 38dvh; }
.viewer-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-select: none; cursor: grab; }
.viewer-placeholder { font-size: 3rem; color: #9AA2B3; }
.viewer-placeholder-text { position: absolute; bottom: 3.5rem; left: 1rem; right: 1rem; margin: 0; text-align: center; color: #C9CED8; font-size: 0.9rem; }
.viewer-reset { position: absolute; top: 0.6rem; right: 0.6rem; display: none; }
.viewer-reset.zoomed { display: inline-flex; }
.viewer-gesture-hint { position: absolute; bottom: 0.5rem; left: 0; right: 0; margin: 0; text-align: center; color: rgba(255, 255, 255, 0.7); font-size: 0.75rem; pointer-events: none; }
.viewer-panel {
    grid-area: panel; max-height: 52dvh; overflow-y: auto; overscroll-behavior: contain;
    display: flex; flex-direction: column; gap: 0.75rem;
    padding: 0.75rem max(var(--gutter), env(safe-area-inset-right, 0px)) calc(0.75rem + var(--safe-bottom)) max(var(--gutter), env(safe-area-inset-left, 0px));
    background: var(--bg); border-top: 1px solid var(--border); box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
}
.viewer-panel .result-card { margin: 0; }
.viewer-panel .result-card.in-viewer .result-head h3 { white-space: normal; }
.viewer-file { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.viewer-done { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.75rem; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--success) 12%, var(--surface)); color: var(--success-text, var(--success)); font-weight: 600; }
.viewer-keys { display: none; flex-wrap: wrap; gap: 0.25rem 0.9rem; margin: 0; color: var(--text-secondary); }
.viewer-keys kbd { display: inline-block; min-width: 1.4em; padding: 0 0.3em; border: 1px solid var(--border-strong, var(--border)); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); color: var(--text); font: inherit; font-size: 0.8rem; text-align: center; }
/* A mouse / trackpad: no swipe hint, the Fit button is always there, and the keys are listed. */
@media (hover: hover) and (pointer: fine) {
    .viewer-gesture-hint { display: none; }
    .viewer-reset { display: inline-flex; }
    .viewer-keys { display: flex; }
}
/* Desktop: the photo on the left, the result on the right. */
@media (min-width: 900px) {
    .photo-viewer { grid-template-columns: minmax(0, 1fr) min(440px, 40vw); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "head head" "stage panel"; }
    .viewer-panel { max-height: none; height: 100%; border-top: 0; border-left: 1px solid var(--border); box-shadow: none; padding: 1rem; }
    .viewer-nav-label { display: inline; }
}

/* ---- reports list: the next step under each unfinished report ------------------------------ */
.doc-next { margin-top: 0.3rem; font-size: 0.85rem; font-weight: 600; color: var(--amber-dark); }
.doc-next.ready { color: var(--success-text, var(--success)); }

}
