/* =====================================================================
   Project RFI - external customer page
   Fluent 2 / Dynamics 365 model-driven form styling.
   Segoe UI, Microsoft neutral ramp, brand blue #0f6cbd, flat sections,
   red asterisk required markers, Fluent text fields and buttons.
   Markup + app.js are unchanged: every selector and [data-*] state is
   restyled here to read like a native Dataverse form.
   ===================================================================== */

:root {
    color-scheme: light;

    /* Fluent 2 neutrals */
    --ink: #242424;              /* neutralForeground1 */
    --ink-soft: #424242;         /* neutralForeground2 */
    --muted: #616161;            /* neutralForeground3 */
    --faint: #707070;
    --disabled: #bdbdbd;
    --line: #edebe9;             /* section dividers (Office neutralLight) */
    --line-2: #e0e0e0;           /* strokes */
    --stroke: #d1d1d1;           /* control stroke */
    --field-line: #8a8886;       /* text field rest border */
    --field-line-hover: #242424;
    --canvas: #f5f5f5;           /* form canvas */
    --surface: #ffffff;
    --subtle: #faf9f8;           /* neutralLighterAlt */
    --subtle-2: #f5f5f5;

    /* Fluent brand (blue) */
    --brand: #0f6cbd;
    --brand-hover: #115ea3;
    --brand-pressed: #0e4775;
    --brand-fg: #ffffff;
    --brand-tint: #eff6fc;       /* selected / subtle brand background */
    --brand-tint-line: #b4d6f5;

    /* Customer voice - a distinct teal so it reads clearly apart from Capricorn blue */
    --teal: #0e6f83;
    --teal-tint: #e5f2f4;
    --teal-line: #bcdde1;

    /* Semantic */
    --success: #0e700e;
    --success-tint: #dff6dd;
    --success-line: #9fd89f;
    --warning: #8a6100;
    --warning-tint: #fff4ce;
    --warning-line: #f2df9a;
    --danger: #b10e1c;
    --danger-tint: #fdf3f4;
    --danger-line: #eeacb2;
    --required: #b10e1c;

    /* Shape + Fluent depth */
    --radius: 4px;
    --radius-lg: 6px;
    --shadow-4: 0 2px 4px rgba(0, 0, 0, .14), 0 0 2px rgba(0, 0, 0, .12);
    --shadow-16: 0 8px 16px rgba(0, 0, 0, .14), 0 0 2px rgba(0, 0, 0, .12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: "Segoe UI", "Segoe UI Web (West European)", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.4286;
}

html,
body {
    width: 100%;
    max-width: 100%;
}

body[data-rfi-loading="true"] .rfi-layout,
body[data-rfi-loading="true"] #link-note,
body[data-rfi-loading="true"] #readonly-note {
    display: none;
}

.rfi-page {
    min-height: 100vh;
    padding: 16px 16px 28px;
}

.rfi-shell {
    width: 100%;
    max-width: 1160px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-4);
    overflow: hidden;
}

/* ---------- Brand / app bar ---------- */
.rfi-card-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 7px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--subtle);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.rfi-brand-mark {
    display: grid;
    grid-template-columns: repeat(3, 4px);
    grid-template-rows: repeat(3, 4px);
    gap: 2px;
    width: 20px;
    height: 20px;
    padding: 3px;
    border-radius: 2px;
    background: var(--brand);
}

.rfi-brand-mark span { background: #ffffff; }
.rfi-brand-mark span:nth-child(1) { grid-row: 1 / span 3; }
.rfi-brand-mark span:nth-child(2) { grid-row: 1 / span 2; }
.rfi-brand-mark span:nth-child(3) { grid-row: 2 / span 2; }

.rfi-brand-copy {
    display: flex;
    align-items: baseline;
    gap: 7px;
    min-width: 0;
}

.rfi-brand-copy strong {
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.rfi-brand-copy span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-brand-context {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.rfi-brand-context::before {
    content: "";
    width: 1px;
    height: 14px;
    margin-right: 10px;
    background: var(--line-2);
}

/* ---------- Form header (record title) ---------- */
.rfi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 56px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

h1, h2 {
    margin: 0;
    line-height: 1.3;
}

h1 {
    color: var(--ink);
    font-size: 20px;
    font-weight: 600;
}

h2 {
    margin-bottom: 12px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.rfi-title-line {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 2px 10px;
    min-width: 0;
}

.rfi-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 400;
}

.rfi-title-line p::before { content: ""; }

.rfi-header-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

/* Status as a Fluent badge (no decorative dot) */
.rfi-status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--subtle-2);
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.rfi-status[data-state="Awaiting Customer"] {
    border-color: var(--brand-tint-line);
    background: var(--brand-tint);
    color: var(--brand);
}

.rfi-status[data-state="Waiting Internal Review"] {
    border-color: var(--warning-line);
    background: var(--warning-tint);
    color: var(--warning);
}

.rfi-status[data-readonly="true"] {
    border-color: var(--success-line);
    background: var(--success-tint);
    color: var(--success);
}

.rfi-due-card {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    min-height: 24px;
    padding: 3px 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--subtle-2);
    white-space: nowrap;
}

.rfi-due-card span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-due-card strong {
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
}

/* ---------- Message bars (notices) ---------- */
.rfi-note {
    margin: 14px 20px 0;
    padding: 9px 12px;
    border: 1px solid var(--brand-tint-line);
    border-radius: var(--radius);
    background: var(--brand-tint);
    color: var(--ink-soft);
    font-size: 13px;
}

.rfi-note strong { color: var(--brand); }

.rfi-note--locked {
    border-color: var(--warning-line);
    background: var(--warning-tint);
    color: #6f4d00;
}

/* ---------- Layout ---------- */
.rfi-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
    padding: 16px 20px 20px;
}

.rfi-main,
.rfi-side { min-width: 0; }

.rfi-page,
.rfi-shell,
.rfi-header,
.rfi-layout,
.rfi-main,
.rfi-side,
.rfi-contact-panel,
.rfi-section,
.rfi-question-response,
.rfi-general-question,
.rfi-upload-panel {
    min-width: 0;
}

.rfi-side {
    display: grid;
    align-content: start;
    gap: 14px;
    padding-left: 20px;
    border-left: 1px solid var(--line);
}

.rfi-side-section { min-width: 0; }

/* Fluent form-section headers: label + hairline divider */
.rfi-side-heading {
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--line);
}

.rfi-side-heading h2 {
    margin: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.rfi-section { margin-bottom: 16px; }

/* ---------- Contact section ---------- */
.rfi-contact-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.rfi-contact-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.rfi-contact-panel .rfi-field {
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: center;
    gap: 8px;
}

.rfi-contact-panel .rfi-field-error {
    grid-column: 2;
}

.rfi-contact-panel input {
    min-height: 30px;
    padding-block: 4px;
}

/* ---------- Fields ---------- */
label {
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.rfi-field {
    display: grid;
    gap: 5px;
    align-content: start;
}

.rfi-label-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
}

/* Required "badge" markup -> Dynamics red asterisk */
.rfi-required-badge {
    display: inline-flex;
    padding: 0;
    border: 0;
    background: none;
    font-size: 0;
    line-height: 1;
}

.rfi-required-badge::before {
    content: "*";
    color: var(--required);
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
}

.rfi-optional-text {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.rfi-field-error {
    display: block;
    margin: 0;
    color: var(--danger);
    font-size: 12px;
    font-weight: 400;
}

.rfi-field-error[hidden] { display: none; }

input,
textarea {
    width: 100%;
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid var(--stroke);
    border-bottom-color: var(--field-line);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    font: inherit;
}

input {
    min-height: 32px;
    margin-top: 0;
}

textarea {
    min-height: 80px;
    padding: 7px 8px;
    resize: vertical;
}

input::placeholder,
textarea::placeholder { color: var(--muted); }

input:hover,
textarea:hover {
    border-color: var(--field-line-hover);
    border-bottom-color: var(--field-line-hover);
}

/* Fluent focus: brand border with 2px brand underline */
input:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: inset 0 -1px 0 0 var(--brand);
}

input.rfi-input-error,
textarea.rfi-input-error {
    border-color: var(--danger);
    border-bottom-color: var(--danger);
}

input.rfi-input-error:focus,
textarea.rfi-input-error:focus {
    border-color: var(--danger);
    box-shadow: inset 0 -1px 0 0 var(--danger);
}

/* ---------- Answer form ---------- */
.rfi-form {
    display: grid;
    gap: 14px;
}

.rfi-form > h2 {
    margin-bottom: 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
    font-size: 15px;
}

.rfi-response-controls {
    display: grid;
    gap: 14px;
}

.rfi-form[data-readonly="true"] .rfi-response-controls { display: none; }

.rfi-question-responses {
    display: grid;
    gap: 14px;
}

/* Flat form sections (no boxed-card look) */
.rfi-question-response,
.rfi-general-question,
.rfi-upload-panel {
    display: grid;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.rfi-question-response > *,
.rfi-general-question > *,
.rfi-upload-panel > * {
    min-width: 0;
    max-width: 100%;
}

.rfi-question-response-head {
    display: grid;
    gap: 3px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
    min-width: 0;
}

.rfi-question-response-head span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-question-response-head strong {
    display: block;
    max-width: 100%;
    color: var(--ink);
    font-size: 16px;
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.rfi-question-response-head .rfi-optional-text {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-question-response-head p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Answer / clarification as two Fluent buttons (default vs accent) */
.rfi-question-choice-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.rfi-question-choice-buttons[hidden] { display: none; }

.rfi-question-choice {
    max-width: 100%;
    min-width: 0;
    min-height: 32px;
    padding: 5px 12px;
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    text-align: center;
    cursor: pointer;
    --neutral-fill-rest: #ffffff;
    --neutral-fill-hover: #f5f5f5;
    --neutral-fill-active: #ebebeb;
    --neutral-stroke-rest: var(--stroke);
    --neutral-stroke-hover: var(--field-line);
    --colorNeutralBackground1: #ffffff;
    --colorNeutralBackground1Hover: #f5f5f5;
    --colorNeutralForeground1: var(--ink);
}

.rfi-question-choice::part(control) {
    min-width: 0;
    max-width: 100%;
}

.rfi-question-choice strong {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.rfi-question-choice:hover { background: #f5f5f5; }

.rfi-question-choice strong { font-weight: 600; }

.rfi-question-choice--active {
    border-color: var(--brand);
    background: var(--brand);
    color: #ffffff;
    --neutral-fill-rest: var(--brand);
    --neutral-fill-hover: var(--brand-hover);
    --neutral-fill-active: var(--brand-pressed);
    --neutral-stroke-rest: var(--brand);
    --neutral-stroke-hover: var(--brand-hover);
    --colorNeutralBackground1: var(--brand);
    --colorNeutralBackground1Hover: var(--brand-hover);
    --colorNeutralForeground1: #ffffff;
}

.rfi-question-choice--active:hover { background: var(--brand-hover); }

.rfi-question-response-label {
    display: block;
    margin-bottom: -4px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.rfi-general-question .rfi-question-response-head {
    padding-bottom: 0;
    border-bottom: 0;
}

.rfi-general-question textarea,
.rfi-general-question-message { min-height: 72px; }

/* ---------- File upload ---------- */
.rfi-upload-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.rfi-upload-head h3 {
    margin: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.rfi-upload-head span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-upload-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.rfi-upload-dropzone {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 3px 12px;
    min-height: 56px;
    padding: 10px 12px;
    border: 1px dashed var(--stroke);
    border-radius: var(--radius);
    background: var(--subtle);
    cursor: pointer;
}

.rfi-upload-dropzone strong { color: var(--ink); font-weight: 600; }

.rfi-upload-dropzone span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-upload-dropzone button {
    grid-row: 1 / span 2;
    grid-column: 2;
}

.rfi-upload-dropzone:hover {
    border-color: var(--brand);
    background: var(--brand-tint);
}

.rfi-upload-dropzone:focus,
.rfi-upload-dropzone:focus-within {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand);
}

.rfi-upload-dropzone--active {
    border-color: var(--brand);
    background: var(--brand-tint);
}

.rfi-upload-list {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.rfi-upload-list:empty { display: none; }

.rfi-upload-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.rfi-upload-list strong {
    display: block;
    color: var(--ink);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.rfi-upload-list span {
    display: block;
    margin-top: 1px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

/* ---------- Read-only answered question ---------- */
.rfi-question {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    margin-bottom: 10px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.rfi-question[data-answered="true"] { border-color: var(--success-line); }

.rfi-question-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 22px;
    padding: 0 8px;
    border-radius: var(--radius);
    background: var(--brand-tint);
    color: var(--brand);
    font-size: 11px;
    font-weight: 600;
}

.rfi-question-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.rfi-question-heading strong {
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.rfi-answer-badge {
    flex: 0 0 auto;
    padding: 2px 9px;
    border: 1px solid var(--success-line);
    border-radius: var(--radius);
    background: var(--success-tint);
    color: var(--success);
    font-size: 12px;
    font-weight: 600;
}

.rfi-question p {
    margin: 5px 0 0;
    color: var(--muted);
}

.rfi-official-answer {
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid var(--success-line);
    border-radius: var(--radius);
    background: var(--success-tint);
}

.rfi-official-answer span {
    display: block;
    margin-bottom: 3px;
    color: var(--success);
    font-size: 12px;
    font-weight: 600;
}

.rfi-official-answer p {
    margin: 0;
    color: var(--ink);
}

.rfi-question-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.rfi-question .rfi-question-files { margin-top: 8px; }

.rfi-question-files li {
    padding: 4px 9px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--subtle-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-question-files a { color: var(--brand); font-weight: 600; }

/* ---------- Submit + result states ---------- */
.rfi-submit-result {
    display: grid;
    gap: 2px;
    padding: 10px 12px;
    border: 1px solid var(--brand-tint-line);
    border-radius: var(--radius);
    background: var(--brand-tint);
}

.rfi-submit-result[hidden] { display: none; }

.rfi-submit-result strong { color: var(--ink); font-size: 14px; font-weight: 600; }
.rfi-submit-result span { color: var(--ink-soft); }

.rfi-submit-result[data-state="pending"] {
    border-color: var(--brand-tint-line);
    background: var(--brand-tint);
}
.rfi-submit-result[data-state="success"] {
    border-color: var(--success-line);
    background: var(--success-tint);
}
.rfi-submit-result[data-state="success"] strong { color: var(--success); }
.rfi-submit-result[data-state="warning"] {
    border-color: var(--warning-line);
    background: var(--warning-tint);
}
.rfi-submit-result[data-state="warning"] strong { color: #6f4d00; }
.rfi-submit-result[data-state="error"] {
    border-color: var(--danger-line);
    background: var(--danger-tint);
}
.rfi-submit-result[data-state="error"] strong,
.rfi-submit-result[data-state="error"] span { color: var(--danger); }

.rfi-form-error-summary {
    padding: 10px 12px;
    border: 1px solid var(--danger-line);
    border-radius: var(--radius);
    background: var(--danger-tint);
    color: var(--danger);
    font-weight: 600;
}
.rfi-form-error-summary[hidden] { display: none; }

.rfi-response-warning {
    padding: 10px 12px;
    border: 1px solid var(--warning-line);
    border-radius: var(--radius);
    background: var(--warning-tint);
    color: #6f4d00;
    font-size: 13px;
}

.rfi-previous-response {
    display: grid;
    gap: 3px;
    padding: 10px 12px;
    border: 1px solid var(--success-line);
    border-radius: var(--radius);
    background: var(--success-tint);
}

.rfi-previous-response span {
    color: var(--success);
    font-size: 12px;
    font-weight: 600;
}

.rfi-previous-response p {
    margin: 0;
    color: var(--ink);
    white-space: pre-line;
}

.rfi-previous-response--clarification {
    border-color: var(--warning-line);
    background: var(--warning-tint);
}
.rfi-previous-response--clarification span { color: #7a5200; }

.rfi-handoff {
    min-height: 18px;
    margin: 0;
    color: var(--success);
    font-weight: 600;
    font-size: 13px;
}

/* ---------- Files from Capricorn ---------- */
.rfi-files {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.rfi-files li {
    display: grid;
    align-items: center;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.rfi-files li.rfi-empty {
    display: block;
    padding: 7px 9px;
    color: var(--muted);
    font-weight: 400;
}

.rfi-files-panel .rfi-side-heading {
    margin-bottom: 6px;
    padding-bottom: 4px;
}

.rfi-files-panel .rfi-side-heading h2 {
    font-size: 13px;
}

/* Collapsible side sections - a way to hide panels to cut noise */
.rfi-side-heading.rfi-collapse-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0 0 8px;
    padding: 0 0 5px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.rfi-side-heading.rfi-collapse-toggle:hover h2 { color: var(--brand); }

.rfi-collapse-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 6px;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--subtle-2);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.rfi-collapse-count:empty { display: none; }

.rfi-collapse-icon {
    flex: 0 0 auto;
    margin-left: auto;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: translateY(-2px) rotate(45deg);
    transition: transform .15s ease;
}

.rfi-collapsible.rfi-collapsed .rfi-collapse-icon {
    transform: translateY(1px) rotate(-45deg);
}

.rfi-collapsible.rfi-collapsed > .rfi-files,
.rfi-collapsible.rfi-collapsed > .rfi-thread {
    display: none;
}

.rfi-file-detail { min-width: 0; }

.rfi-file-detail strong,
.rfi-file-detail a {
    display: block;
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.rfi-file-detail a { color: var(--brand); }

.rfi-file-detail span {
    display: block;
    margin-top: 1px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
}

/* ---------- Conversation (timeline) ---------- */
.rfi-thread { display: grid; gap: 8px; }

.rfi-thread-empty {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--subtle);
    color: var(--muted);
    font-weight: 400;
}

.rfi-message {
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.rfi-message-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.rfi-message-sender {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.rfi-message-source {
    display: inline-flex;
    align-items: center;
    min-height: 18px;
    padding: 1px 7px;
    border: 1px solid var(--brand-tint-line);
    border-radius: var(--radius);
    background: var(--brand-tint);
    color: var(--brand);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}

/* Colour-code the two parties so it is clear who said what */
.rfi-message[data-source="internal"] { border-left: 3px solid var(--brand); }
.rfi-message[data-source="external"] { border-left: 3px solid var(--teal); }

.rfi-message[data-source="external"] .rfi-message-source {
    border-color: var(--teal-line);
    background: var(--teal-tint);
    color: var(--teal);
}

/* The "Capricorn" sender name just repeats its own chip - drop it as noise */
.rfi-message[data-source="internal"] .rfi-message-head strong { display: none; }

.rfi-message[data-source="system"] .rfi-message-source {
    border-color: var(--success-line);
    background: var(--success-tint);
    color: var(--success);
}

/* Quieter status lines so the real back-and-forth stands out (denoise) */
.rfi-message[data-source="system"] {
    padding: 5px 10px;
    border: 0;
    border-left: 2px solid var(--line-2);
    border-radius: 0;
    background: transparent;
}

.rfi-message[data-source="system"] .rfi-message-head { margin-bottom: 2px; }

.rfi-message[data-source="system"] .rfi-message-head strong { display: none; }

.rfi-message[data-source="system"] .rfi-message-source {
    padding-inline: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
}

.rfi-message[data-source="system"] .rfi-message-body p {
    color: var(--muted);
    font-size: 12px;
}

/* Files attached inside an answer/clarification block sit tight to it */
.rfi-message-qblock .rfi-message-attachments { margin-top: 6px; }

.rfi-message-head strong {
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.rfi-message-head time {
    flex: 0 0 auto;
    padding-top: 1px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.rfi-message-body p {
    margin: 0 0 7px;
    color: var(--ink-soft);
    white-space: pre-line;
}

.rfi-message-body p:last-child { margin-bottom: 0; }

.rfi-message-attachments {
    display: grid;
    gap: 5px;
    margin-top: 8px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--subtle);
}

.rfi-message-attachments > strong {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.rfi-message-attachments ul {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.rfi-message-attachments li { overflow-wrap: anywhere; }
.rfi-message-attachments a { color: var(--brand); font-weight: 600; }

.rfi-message-qblock { display: grid; gap: 5px; }

.rfi-message-qblock--question {
    padding: 8px 10px;
    border: 1px solid var(--warning-line);
    border-radius: var(--radius);
    background: var(--warning-tint);
}

.rfi-message-qblock--question .rfi-message-question strong { color: var(--warning); }

.rfi-message-question { display: grid; gap: 1px; }

.rfi-message-question strong {
    color: var(--ink);
    font-size: 11px;
    font-weight: 600;
}

.rfi-message-question span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

/* ---------- Buttons (Fluent) ---------- */
button { font: inherit; cursor: pointer; }

/* Primary accent CTA (Fluent button). The v3 component leaves the host
   background transparent unless a theme provider resolves its design
   tokens, so we paint the host directly (this is what reliably renders,
   same as the choice buttons) and also set the brand tokens as a bonus. */
fluent-button.rfi-submit {
    min-width: 96px;
    min-height: 32px;
    padding: 5px 16px;
    border: 1px solid var(--brand);
    border-radius: var(--radius);
    background: var(--brand);
    color: #ffffff;
    font-weight: 600;
    --accent-fill-rest: var(--brand);
    --accent-fill-hover: var(--brand-hover);
    --accent-fill-active: var(--brand-pressed);
    --accent-stroke-control-rest: var(--brand);
    --colorBrandBackground: var(--brand);
    --colorBrandBackgroundHover: var(--brand-hover);
    --colorBrandBackgroundPressed: var(--brand-pressed);
    --colorNeutralForegroundOnBrand: #ffffff;
}

fluent-button.rfi-submit:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
}

fluent-button.rfi-submit[disabled],
fluent-button.rfi-submit:disabled {
    background: var(--brand);
    border-color: var(--brand);
}

/* Default (secondary) buttons */
.rfi-upload-dropzone button,
.rfi-photo-modal__close,
.rfi-upload-remove {
    min-height: 32px;
    padding: 5px 14px;
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    font-weight: 600;
}

.rfi-upload-dropzone button:hover,
.rfi-photo-modal__close:hover,
.rfi-upload-remove:hover {
    background: var(--subtle-2);
    border-color: var(--field-line);
}

/* Link-style file preview */
button.rfi-file-preview {
    display: block;
    max-width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--brand);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    overflow-wrap: anywhere;
}

button.rfi-file-preview:hover,
button.rfi-file-preview:focus { text-decoration: underline; }

.rfi-photo-hover[hidden] { display: none; }

.rfi-photo-hover {
    position: fixed;
    z-index: 900;
    width: min(260px, calc(100vw - 24px));
    padding: 8px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: #ffffff;
    box-shadow: 0 14px 32px rgba(35, 14, 55, .18);
    pointer-events: none;
}

.rfi-photo-hover img {
    display: block;
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    border-radius: 4px;
    background: var(--subtle);
}

.rfi-photo-hover span {
    display: block;
    margin-top: 6px;
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

button:disabled,
fluent-button:disabled,
fluent-button[disabled],
input:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: .55;
}

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

/* ---------- Photo modal ---------- */
.rfi-photo-modal[hidden],
.rfi-answer-modal[hidden] { display: none; }

body.rfi-photo-modal-open,
body.rfi-answer-modal-open { overflow: hidden; }

.rfi-photo-modal,
.rfi-answer-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
}

.rfi-photo-modal__backdrop,
.rfi-answer-modal__backdrop {
    position: absolute;
    inset: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(0, 0, 0, .4);
    cursor: pointer;
}

.rfi-photo-modal__dialog {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: min(960px, 100%);
    max-height: min(88vh, 820px);
    overflow: hidden;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-lg);
    background: #ffffff;
    box-shadow: var(--shadow-16);
}

.rfi-answer-modal__dialog {
    position: relative;
    z-index: 1;
    display: grid;
    width: min(540px, 100%);
    max-height: min(88vh, 680px);
    overflow: hidden;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-lg);
    background: #ffffff;
    box-shadow: var(--shadow-16);
}

.rfi-photo-modal__header,
.rfi-answer-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.rfi-photo-modal__header h2,
.rfi-answer-modal__header h2 { margin: 0; overflow-wrap: anywhere; }

.rfi-answer-modal__body {
    display: grid;
    gap: 12px;
    overflow: auto;
    padding: 14px 16px 16px;
}

.rfi-answer-modal__body p {
    margin: 0;
    color: var(--ink-soft);
}

.rfi-answer-modal__current {
    display: grid;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--warning-line);
    border-radius: var(--radius);
    background: var(--warning-tint);
}

.rfi-answer-modal__current strong {
    color: #6f4d00;
    font-size: 12px;
}

.rfi-answer-modal__current p {
    margin: 0;
    color: var(--ink);
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.rfi-answer-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
}

.rfi-photo-modal__media {
    display: grid;
    place-items: center;
    min-height: 260px;
    overflow: auto;
    padding: 16px;
    background: #201f1e;
}

.rfi-photo-modal__media img {
    display: block;
    max-width: 100%;
    max-height: calc(88vh - 150px);
    object-fit: contain;
}

.rfi-photo-modal__media p {
    max-width: 520px;
    margin: 0;
    padding: 16px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--ink);
    font-weight: 600;
    text-align: center;
}

.rfi-photo-modal__original {
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    color: var(--brand);
    font-weight: 600;
}

.rfi-answer-modal__secondary,
.rfi-answer-modal__primary {
    min-height: 32px;
    padding: 5px 14px;
    border-radius: var(--radius);
    font-weight: 600;
}

.rfi-answer-modal__secondary {
    border: 1px solid var(--stroke);
    background: #ffffff;
    color: var(--ink);
}

.rfi-answer-modal__secondary:hover {
    background: var(--subtle-2);
    border-color: var(--field-line);
}

.rfi-answer-modal__primary {
    border: 1px solid var(--brand);
    background: var(--brand);
    color: #ffffff;
}

.rfi-answer-modal__primary:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .rfi-page { padding: 10px 10px 20px; }
    .rfi-card-brand { padding-inline: 14px; }
    .rfi-header { padding: 12px 14px; min-height: 0; }

    .rfi-layout {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 14px;
    }

    .rfi-side {
        display: grid;
        order: 1;
        gap: 16px;
        padding-left: 0;
        border-left: 0;
    }

    .rfi-main { order: 0; }
    .rfi-contact-panel {
        grid-template-columns: 1fr;
        order: -1;
        padding: 10px 14px;
    }

    .rfi-contact-panel h2 {
        padding: 0 0 5px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .rfi-contact-panel .rfi-field {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    .rfi-contact-panel .rfi-field-error {
        grid-column: 1;
    }

    .rfi-side-section { width: 100%; }
    .rfi-note { margin-inline: 14px; }
    .rfi-contact-fields { grid-template-columns: 1fr; }
    .rfi-question-choice-buttons { grid-template-columns: 1fr; }

    .rfi-upload-head,
    .rfi-upload-dropzone { grid-template-columns: 1fr; }
    .rfi-upload-head { display: grid; gap: 2px; }
    .rfi-upload-dropzone button { grid-row: auto; grid-column: auto; width: 100%; }

    fluent-button.rfi-submit { width: 100%; }

    .rfi-photo-modal { padding: 12px; }
    .rfi-photo-modal__dialog { max-height: 92vh; }
    .rfi-photo-modal__media { min-height: 220px; padding: 10px; }
    .rfi-photo-modal__media img { max-height: calc(92vh - 140px); }
    .rfi-answer-modal { padding: 12px; }
    .rfi-answer-modal__actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (max-width: 620px) {
    .rfi-page { padding-inline: 0; }

    .rfi-shell {
        border-right: 0;
        border-left: 0;
        border-radius: 0;
    }

    .rfi-card-brand {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 4px 9px;
    }

    .rfi-brand-copy {
        min-width: 0;
        flex-wrap: wrap;
        gap: 1px 6px;
    }

    .rfi-brand-copy strong,
    .rfi-brand-copy span,
    .rfi-brand-context,
    .rfi-subtitle,
    h1 {
        overflow-wrap: anywhere;
    }

    .rfi-brand-context {
        grid-column: 1 / -1;
        margin-left: 0;
        white-space: normal;
    }

    .rfi-brand-context::before { display: none; }

    .rfi-header { align-items: flex-start; flex-wrap: wrap; }
    .rfi-title-line { width: 100%; }
    .rfi-header-meta {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
        gap: 7px;
    }

    .rfi-status,
    .rfi-due-card {
        width: 100%;
        min-width: 0;
        justify-content: center;
        white-space: normal;
        text-align: center;
    }

    .rfi-question {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .rfi-question-response,
    .rfi-general-question,
    .rfi-upload-panel,
    .rfi-contact-panel {
        padding: 12px;
    }

    h1 { font-size: 18px; }
}
