.referral-count{padding:12px 14px;border:1px solid var(--line);border-radius:10px;background:var(--surface);font-weight:600;line-height:1.7}
.referral-gallery{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,190px),1fr));gap:16px;margin:16px 0 24px;list-style:none;padding:0;align-items:start}
.referral-gallery .referral-card{display:flex;flex-direction:column;align-items:stretch;gap:0;min-width:0;padding:0;margin:0;overflow:hidden;border:1px solid var(--line);border-radius:12px;background:#fff}
.referral-gallery .referral-card+.referral-card{margin-top:0}
.referral-thumbnail{display:flex;position:relative;align-items:center;justify-content:center;width:100%;height:190px;min-height:0;padding:10px;border:0;border-bottom:1px solid var(--line);border-radius:0;background:#edf1f5;color:var(--brand-dark);overflow:hidden;cursor:zoom-in}
.referral-thumbnail:hover{background:#e4eaf1;color:var(--brand-dark)}
.referral-thumbnail:focus-visible{outline:3px solid var(--brand-dark);outline-offset:-4px}
.referral-thumbnail img,.referral-thumbnail canvas{display:block;max-width:100%;max-height:100%;width:auto;height:auto;object-fit:contain;box-shadow:0 2px 8px #1830441a}
.referral-thumbnail [hidden]{display:none}
.referral-preview-fallback{display:flex;align-items:center;justify-content:center;min-width:78px;min-height:98px;border:2px solid #b4c0cf;border-radius:5px;background:#fff;color:#4b6077;font-weight:700;font-size:15px;letter-spacing:.05em}
.referral-thumbnail-label{position:absolute;bottom:9px;right:9px;padding:5px 10px;border:1px solid #d3dbe4;border-radius:20px;background:#fffffff2;color:#263445;font-size:11px;font-weight:600;line-height:1.5}
.referral-card-body{padding:14px;min-width:0}
.referral-card-body .file-name{display:block;max-width:none;font-size:12px;line-height:1.6;overflow-wrap:anywhere}
.referral-card-body [data-preview-status]{margin:6px 0 12px;line-height:1.65;min-height:2.5em}
.referral-card .document-actions{justify-content:flex-start;gap:8px}
.referral-card :is(.document-actions button,.document-actions .button,.referral-card-body>button){min-height:44px;padding:9px 13px;font-size:11px}
.document-removal-confirmation{flex:1 0 100%;min-width:0;padding:12px;margin-top:4px;border:1px solid #efc6cb;border-radius:9px;background:#fff7f7}
.document-removal-confirmation[hidden]{display:none}
.document-removal-confirmation p{margin:0 0 10px;font-size:12px;line-height:1.65;overflow-wrap:anywhere}
.document-removal-confirmation .actions{margin-top:12px;gap:8px}
.document-removal-confirmation .actions button{width:100%;white-space:normal}
.document-removal-confirmation [role=status]:empty{display:none}
@media(forced-colors:active){.document-removal-confirmation{background:Canvas;border-color:CanvasText}}
:is(#uploadForm,#additionalUploadForm) .upload-queue{margin-top:16px;background:#f7f9fb}
:is(#uploadForm,#additionalUploadForm) .upload-queue>.referral-gallery{margin-bottom:0}
:is(#uploadForm,#additionalUploadForm) .actions{margin-top:18px}

/* Stan operacji pozostaje widoczny również podczas wymiany zawartości main. */
.operation-status{position:fixed;left:50%;bottom:20px;transform:translateX(-50%);display:flex;align-items:flex-start;gap:15px;width:min(540px,calc(100% - 32px));padding:18px 20px;border:1px solid #b7c6d7;border-left:4px solid var(--brand);border-radius:12px;background:#fff;color:#323d4f;box-shadow:0 10px 36px #20344e30;z-index:30;pointer-events:none}
.operation-status[hidden]{display:none}
.operation-status>div{min-width:0;flex:1}
.operation-status-message{margin:0;font-size:14px;line-height:1.65;font-weight:600}
.operation-status-hint{display:block;font-size:12px;line-height:1.6;color:var(--muted);margin-top:4px}
.operation-status progress{display:block;width:100%;height:9px;margin:11px 0 8px;accent-color:var(--brand)}
.operation-status progress[hidden]{display:none}
.operation-spinner{flex:0 0 24px;width:24px;height:24px;margin-top:2px;border:3px solid #d9e2ec;border-top-color:var(--brand);border-radius:50%;animation:mp3-operation-spin .85s linear infinite}
@keyframes mp3-operation-spin{to{transform:rotate(360deg)}}

/* Natywny modal utrzymuje fokus, obsługuje Escape i nie udostępnia tła. */
.referral-preview-dialog{width:min(1160px,calc(100vw - 32px));max-width:none;height:min(900px,calc(100dvh - 40px));max-height:none;padding:0;border:1px solid #c6d0dc;border-radius:15px;background:#fff;color:#323d4f;box-shadow:0 16px 80px #15284170}
.referral-preview-dialog::backdrop{background:#12263bd1}
.referral-preview-shell{display:flex;flex-direction:column;height:100%;min-height:0}
.referral-preview-header{display:flex;align-items:flex-start;justify-content:space-between;gap:18px;padding:19px 22px 12px;border-bottom:1px solid var(--line)}
.referral-preview-header>div{min-width:0}
.referral-preview-header h2{font-size:17px;line-height:1.5;margin:0;overflow-wrap:anywhere}
.referral-preview-header p{margin:6px 0 0}
.referral-preview-header>button{min-height:44px;padding:10px 17px;flex:none}
.referral-preview-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:8px;padding:12px 22px;border-bottom:1px solid var(--line)}
.referral-preview-toolbar button{min-height:42px;padding:9px 14px;font-size:12px}
.referral-preview-toolbar-gap{flex:1}
.referral-preview-status{padding:12px 22px;font-size:13px;color:var(--muted);line-height:1.7}
.referral-preview-status:empty{display:none}
.referral-preview-viewport{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;padding:12px;background:#e7ecf2;outline-offset:-4px}
.referral-preview-viewport img,.referral-preview-viewport canvas{display:block;margin:0 auto;background:#fff;box-shadow:0 2px 13px #25394f30}
.referral-preview-viewport img{object-fit:contain}
.referral-preview-viewport [hidden]{display:none}
.referral-preview-viewport:focus-visible{outline:3px solid var(--brand-dark)}
body.high-contrast :is(.referral-card,.referral-thumbnail,.referral-count,.referral-preview-dialog,.operation-status){background:#000;color:#fff;border-color:#fff}
body.high-contrast .referral-thumbnail-label{background:#000;color:#fff;border-color:#fff}
body.high-contrast .referral-preview-viewport{background:#222}
body.high-contrast :is(.referral-card .muted,.referral-preview-dialog .muted,.referral-preview-status,.operation-status-hint){color:#fff}
body.high-contrast .operation-spinner{border-color:#777;border-top-color:#fff}
body.large-text .referral-preview-dialog :is(button,p){font-size:1.05rem}
@media(max-width:760px){.referral-gallery{grid-template-columns:repeat(auto-fit,minmax(min(100%,170px),1fr));gap:12px}.referral-thumbnail{height:175px}.referral-card-body{padding:12px}.operation-status{padding:14px 16px;bottom:12px;gap:12px}.operation-status-message{font-size:13px}.referral-preview-dialog{width:calc(100vw - 16px);height:calc(100dvh - 20px);border-radius:10px}.referral-preview-header{padding:14px 14px 10px;gap:10px}.referral-preview-header h2{font-size:14px}.referral-preview-header>button{padding-inline:12px;font-size:12px}.referral-preview-toolbar{padding:10px 14px;gap:6px}.referral-preview-toolbar button{padding:9px 11px;min-height:44px}.referral-preview-toolbar-gap{flex-basis:100%;height:0}.referral-preview-status{padding:10px 14px}.referral-preview-viewport{padding:8px}}
@media(prefers-reduced-motion:reduce){.operation-spinner{animation:none;border-style:dotted;border-top-style:solid}}
@media(forced-colors:active){.referral-card,.referral-count,.referral-thumbnail,.operation-status,.referral-preview-dialog{border-color:CanvasText;background:Canvas;color:CanvasText}.referral-preview-fallback,.referral-thumbnail-label{border-color:CanvasText;background:Canvas;color:CanvasText}.operation-spinner{border-color:CanvasText;border-top-color:Highlight}}
