/* Patient Upload Portal - patient page styles.
 * Copyright (c) 2026
 *
 * Neutral practice branding, deliberately calm and trustworthy: warm paper
 * ground, deep petrol ink, one amber accent. IBM Plex (OFL, see
 * fonts/LICENSE.txt) is self-hosted - no third-party font requests (GDPR).
 * Chinese falls back to the platform's CJK fonts to keep the page light.
 * All spacing uses logical properties so the Arabic RTL layout mirrors
 * correctly.
 */

@font-face {
	font-family: "IBM Plex Serif";
	font-weight: 600;
	font-display: swap;
	src: url("../fonts/IBMPlexSerif-SemiBold.woff2") format("woff2");
}
@font-face {
	font-family: "IBM Plex Serif";
	font-weight: 700;
	font-display: swap;
	src: url("../fonts/IBMPlexSerif-Bold.woff2") format("woff2");
}
@font-face {
	font-family: "IBM Plex Sans";
	font-weight: 400;
	font-display: swap;
	src: url("../fonts/IBMPlexSans-Regular.woff2") format("woff2");
}
@font-face {
	font-family: "IBM Plex Sans";
	font-weight: 600;
	font-display: swap;
	src: url("../fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
}
@font-face {
	font-family: "IBM Plex Sans Arabic";
	font-weight: 400;
	font-display: swap;
	src: url("../fonts/IBMPlexSansArabic-Regular.woff2") format("woff2");
}
@font-face {
	font-family: "IBM Plex Sans Arabic";
	font-weight: 600;
	font-display: swap;
	src: url("../fonts/IBMPlexSansArabic-SemiBold.woff2") format("woff2");
}

:root {
	--paper: #f6f1e7;
	--card: #fffdf8;
	--ink: #182528;
	--ink-soft: #46595e;
	--petrol: #0e4d5c;
	--petrol-deep: #093642;
	--amber: #d9772a;
	--amber-soft: #f3d9bf;
	--ok: #2c7a4b;
	--warn: #b3541e;
	--danger: #a4303f;
	--hairline: #d9cfbc;
	--radius: 14px;
	--font-display: "IBM Plex Serif", "IBM Plex Sans Arabic", Georgia, "Times New Roman", serif;
	--font-body: "IBM Plex Sans", "IBM Plex Sans Arabic", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Author display values (e.g. the loading grid) must never beat [hidden]. */
[hidden] { display: none !important; }

/* Script-focused anchors (screen headings, the spinner, the summary line)
 * are unreachable by Tab; a focus ring on them signals nothing and only
 * real controls should show one. */
[tabindex="-1"]:focus { outline: none; }

/* Visually hidden but still exposed to screen readers (headings, the live
 * announcer region). Never combine with [hidden] - that silences it. */
.sr-only {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

html, body { margin: 0; padding: 0; }

body {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	font-family: var(--font-body);
	font-size: 17px;
	line-height: 1.55;
	color: var(--ink);
	background-color: var(--paper);
	background-image:
		radial-gradient(1100px 500px at 85% -10%, color-mix(in srgb, var(--petrol) 12%, transparent), transparent 60%),
		radial-gradient(900px 600px at -10% 110%, color-mix(in srgb, var(--amber) 10%, transparent), transparent 55%),
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.03 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- Masthead ---- */

.masthead {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 1.1rem clamp(1rem, 4vw, 2.5rem);
	border-block-end: 1px solid var(--hairline);
	background: color-mix(in srgb, var(--card) 75%, transparent);
}

.brand { display: flex; align-items: center; gap: 0.7rem; }

.brand-mark {
	inline-size: 30px;
	block-size: 30px;
	border-radius: 9px 9px 9px 2px;
	background: linear-gradient(135deg, var(--petrol) 0 55%, var(--amber) 55% 100%);
	box-shadow: 0 2px 6px color-mix(in srgb, var(--petrol-deep) 35%, transparent);
}

.brand-name {
	font-family: var(--font-display);
	font-size: 1.25rem;
	font-weight: 700;
	letter-spacing: 0.01em;
	color: var(--petrol-deep);
}

/* Stretch, not center: the badge always matches the picker button's height. */
.masthead-side { display: flex; align-items: stretch; gap: 0.9rem; }

.secure-badge {
	display: inline-flex;
	align-items: center;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--petrol);
	border: 1px solid var(--petrol);
	border-radius: 999px;
	padding: 0 0.8rem;
	background: color-mix(in srgb, var(--petrol) 6%, transparent);
}

.language-switch {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-display);
	font-size: 1rem;
	font-weight: 600;
	color: var(--petrol-deep);
	background: none;
	border: 1px solid var(--hairline);
	border-radius: 8px;
	padding: 0.3rem 0.6rem;
	cursor: pointer;
}
.language-switch:hover { border-color: var(--petrol); }

/* ---- Screens ---- */

main {
	flex: 1;
	inline-size: min(720px, 100% - 2rem);
	margin-inline: auto;
	padding-block: clamp(1.5rem, 5vh, 4rem) 2rem;
}

.screen {
	background: var(--card);
	border: 1px solid var(--hairline);
	border-inline-start: 6px solid var(--petrol);
	border-radius: var(--radius);
	padding: clamp(1.5rem, 5vw, 3rem);
	box-shadow:
		0 1px 2px color-mix(in srgb, var(--ink) 6%, transparent),
		0 18px 45px -18px color-mix(in srgb, var(--petrol-deep) 35%, transparent);
}

.screen > * {
	animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.screen > *:nth-child(2) { animation-delay: 0.07s; }
.screen > *:nth-child(3) { animation-delay: 0.14s; }
.screen > *:nth-child(4) { animation-delay: 0.21s; }
.screen > *:nth-child(5) { animation-delay: 0.28s; }
.screen > *:nth-child(n+6) { animation-delay: 0.35s; }

@keyframes rise {
	from { opacity: 0; transform: translateY(14px); }
	to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
	.screen > * { animation: none; }
	.overall-bar, .file-progress-bar { transition: none; }
}

h1 {
	font-family: var(--font-display);
	font-size: clamp(1.7rem, 4.5vw, 2.4rem);
	line-height: 1.15;
	color: var(--petrol-deep);
	margin: 0 0 0.8rem;
}

.lede { color: var(--ink-soft); margin-block: 0 1.8rem; max-inline-size: 46ch; }

/* ---- Language picker ---- */

.language-kicker {
	color: var(--ink-soft);
	font-size: 0.95rem;
	text-align: center;
	margin-block: 0 1.2rem;
}

.language-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
	gap: 0.9rem;
}

.language-button {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.45rem;
	font-family: var(--font-display);
	font-weight: 600;
	font-size: 1.35rem;
	padding: 1.1rem 1rem 0.9rem;
	color: var(--petrol-deep);
	background: var(--paper);
	border: 1.5px solid var(--hairline);
	border-radius: 12px;
	cursor: pointer;
	transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

/* The flag row keeps one height whether a language shows one flag or three. */
.language-flags {
	display: flex;
	gap: 0.35rem;
	block-size: 15px;
}

.language-flags img {
	inline-size: 20px;
	block-size: 15px;
	border-radius: 2px;
	box-shadow: 0 0 0 1px var(--hairline);
}

.language-button:hover, .language-button:focus-visible {
	border-color: var(--amber);
	background: var(--amber-soft);
	transform: translateY(-2px);
}

/* ---- Loading / error ---- */

#screen-loading { display: grid; place-items: center; min-block-size: 220px; }

.spinner {
	inline-size: 44px;
	block-size: 44px;
	border: 4px solid var(--hairline);
	border-block-start-color: var(--petrol);
	border-radius: 50%;
	animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Icon and title share the first row; the explanation spans below them. */
#screen-error {
	display: grid;
	grid-template-columns: auto 1fr;
	align-items: center;
	column-gap: 1.1rem;
}

#screen-error h1 { margin-block: 0; }

#screen-error .lede {
	grid-column: 1 / -1;
	margin-block: 1.2rem 0;
}

.error-mark {
	inline-size: 54px;
	block-size: 54px;
	display: grid;
	place-items: center;
	font-family: var(--font-display);
	font-size: 2rem;
	font-weight: 700;
	color: #fff;
	background: var(--danger);
	border-radius: 50%;
}

/* ---- Access code ---- */

.code-form { display: flex; gap: 0.8rem; flex-wrap: wrap; }

.code-form input {
	flex: 1 1 220px;
	font-size: 1.5rem;
	font-family: var(--font-display);
	font-weight: 600;
	letter-spacing: 0.35em;
	text-transform: uppercase;
	padding: 0.7rem 1rem;
	border: 1.5px solid var(--hairline);
	border-radius: 10px;
	background: var(--paper);
	color: var(--ink);
	min-inline-size: 0;
}
.code-form input:focus-visible { outline: 3px solid color-mix(in srgb, var(--petrol) 35%, transparent); border-color: var(--petrol); }

button.primary, .code-form button {
	font-size: 1.05rem;
	font-weight: 600;
	color: #fff;
	background: var(--petrol);
	border: none;
	border-radius: 10px;
	padding: 0.8rem 1.8rem;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.1s ease;
}
button.primary:hover:not(:disabled, [aria-disabled="true"]), .code-form button:hover:not(:disabled) { background: var(--petrol-deep); }
button.primary:active:not(:disabled, [aria-disabled="true"]) { transform: translateY(1px); }
/* The confirmation gate uses aria-disabled so the button stays focusable
 * and can explain itself; it must look exactly like a :disabled one. */
button.primary:disabled, button.primary[aria-disabled="true"],
.code-form button:disabled { background: var(--hairline); color: var(--ink-soft); cursor: not-allowed; }

.field-error { color: var(--danger); font-weight: 600; }

/* ---- Dropzone ---- */

.dropzone {
	border: 2px dashed var(--petrol);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--petrol) 4.5%, transparent);
	padding: clamp(1.2rem, 4vw, 2.2rem);
	text-align: center;
	transition: background 0.15s ease, border-color 0.15s ease;
}
.dropzone.drag-active { background: var(--amber-soft); border-color: var(--amber); }

.drop-hint { font-size: 1.1rem; font-weight: 600; color: var(--petrol-deep); margin-block: 0 1rem; }
.drop-note { font-size: 0.9rem; color: var(--ink-soft); margin-block: 1rem 0; }

.pick-buttons { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; }

.pick-buttons button {
	font-size: 1rem;
	font-weight: 600;
	color: var(--petrol-deep);
	background: var(--card);
	border: 1.5px solid var(--petrol);
	border-radius: 10px;
	padding: 0.65rem 1.3rem;
	cursor: pointer;
	transition: background 0.15s ease;
}
.pick-buttons button:hover { background: var(--amber-soft); border-color: var(--amber); }

/* ---- File list ---- */

.file-summary { font-weight: 600; color: var(--petrol-deep); margin-block: 1.4rem 0.6rem; }

.file-list { list-style: none; margin: 0; padding: 0; }

.file-row {
	display: grid;
	grid-template-columns: auto 1fr auto auto auto;
	grid-template-areas: "kind name size status remove" "bar bar bar bar bar";
	align-items: center;
	gap: 0.35rem 0.9rem;
	padding: 0.65rem 0.2rem;
	border-block-end: 1px solid var(--hairline);
}

.file-kind {
	grid-area: kind;
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	padding: 0.15rem 0.5rem;
	border-radius: 6px;
	color: #fff;
	background: var(--ink-soft);
}
.kind-dicom { background: var(--petrol); }
.kind-pdf { background: var(--danger); }
.kind-photo { background: var(--amber); }

.file-name {
	grid-area: name;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	direction: ltr;          /* file names stay LTR even in RTL locales */
	text-align: start;
}

.file-size { grid-area: size; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.file-status { grid-area: status; font-size: 0.9rem; font-weight: 600; display: flex; gap: 0.5rem; align-items: center; }
.file-done .file-status { color: var(--ok); }
.file-failed .file-status, .file-rejected .file-status { color: var(--danger); }

.retry-button {
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--petrol);
	background: none;
	border: 1px solid var(--petrol);
	border-radius: 6px;
	padding: 0.1rem 0.6rem;
	cursor: pointer;
}

.file-remove {
	grid-area: remove;
	display: grid;
	place-items: center;
	inline-size: 1.7rem;
	block-size: 1.7rem;
	padding: 0;
	color: var(--ink-soft);
	background: none;
	border: 1px solid var(--hairline);
	border-radius: 6px;
	cursor: pointer;
	transition: color 0.15s ease, border-color 0.15s ease;
}
.file-remove:hover { color: var(--danger); border-color: var(--danger); }
.file-uploading .file-remove,
.file-done .file-remove,
.file-failed .file-remove,
.upload-running .file-remove { display: none; }

.file-progress { grid-area: bar; block-size: 5px; background: var(--paper); border-radius: 3px; overflow: hidden; }
.file-progress-bar {
	block-size: 100%;
	inline-size: 0%;
	background: linear-gradient(90deg, var(--petrol), var(--amber));
	border-radius: 3px;
	transition: width 0.25s ease;
}
.file-rejected .file-progress { visibility: hidden; }

/* ---- DICOM confirmation ---- */

.dicom-confirm {
	margin-block-start: 1.4rem;
	padding: 0.9rem 1.1rem;
	background: var(--amber-soft);
	border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
	border-radius: var(--radius);
}

.confirm-title { margin: 0 0 0.4rem; font-weight: 600; color: var(--petrol-deep); }

.identity-list { list-style: none; margin: 0 0 0.7rem; padding: 0; }
.identity-list li { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: baseline; padding-block: 0.15rem; }
.identity-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; color: var(--petrol-deep); }
.identity-meta { color: var(--ink-soft); }

.confirm-check { display: flex; gap: 0.55rem; align-items: flex-start; cursor: pointer; }
.confirm-check input { margin-block-start: 0.25rem; accent-color: var(--petrol); }

/* ---- DICOM study/series view ---- */

.study-list { margin-block-end: 0.4rem; }

.study {
	border: 1px solid var(--hairline);
	border-radius: calc(var(--radius) - 4px);
	background: color-mix(in srgb, var(--petrol) 3%, var(--card));
	margin-block-end: 0.8rem;
}

.study-header {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 0.9rem;
	align-items: baseline;
	padding: 0.65rem 0.9rem;
	cursor: pointer;
	list-style-position: outside;
}
.study-patient { font-family: var(--font-display); font-weight: 600; color: var(--petrol-deep); }
.study-meta { color: var(--ink-soft); }
.study-counts { color: var(--ink-soft); font-size: 0.9rem; margin-inline-start: auto; }
.study-header .file-remove { align-self: center; }

.series-list {
	list-style: none;
	margin: 0;
	padding: 0 0.9rem 0.7rem;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.8rem;
}

.series-tile {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	padding: 0.55rem;
	background: var(--card);
	border: 1px solid var(--hairline);
	border-radius: calc(var(--radius) - 6px);
}

.series-thumb {
	display: grid;
	place-items: center;
	inline-size: 100%;
	aspect-ratio: 1;
	padding: 0;
	color: var(--ink-soft);
	background: var(--paper);
	border: 1px solid var(--hairline);
	border-radius: 6px;
	overflow: hidden;
	cursor: zoom-in;
}
.series-thumb img { inline-size: 100%; block-size: 100%; object-fit: contain; }

.series-main { display: flex; flex-direction: column; gap: 0.1rem; min-inline-size: 0; }
.series-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.series-counts { color: var(--ink-soft); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

.series-status { font-size: 0.85rem; }
.series-done .series-status { color: var(--ok); }
.series-failed .series-status { color: var(--danger); }

.series-tile .file-remove {
	position: absolute;
	inset-block-start: 0.85rem;
	inset-inline-end: 0.85rem;
	background: var(--card);
}
.series-tile .file-progress { margin-block-start: auto; }
.series-uploading .file-remove,
.series-done .file-remove { display: none; }

.dir-list { list-style: none; margin: 0; padding: 0 0.9rem 0.6rem; }
.dir-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.9rem;
	padding: 0.35rem 0.2rem;
	border-block-start: 1px dashed var(--hairline);
	color: var(--ink-soft);
	font-size: 0.9rem;
}
.dir-done .dir-status { color: var(--ok); }
.dir-failed .dir-status { color: var(--danger); }

.skipped-note { color: var(--ink-soft); font-size: 0.9rem; margin-block: 0.2rem 0.6rem; }

/* ---- Overall progress / actions ---- */

.overall { margin-block-start: 1.6rem; }
.overall-track { block-size: 12px; background: var(--paper); border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden; }
.overall-bar {
	block-size: 100%;
	inline-size: 0%;
	border-radius: 8px;
	background:
		linear-gradient(90deg, rgba(255,255,255,0) 0 40%, rgba(255,255,255,0.35) 50%, rgba(255,255,255,0) 60% 100%),
		linear-gradient(90deg, var(--petrol), var(--amber));
	background-size: 200% 100%, 100% 100%;
	animation: shimmer 1.6s linear infinite;
	transition: width 0.3s ease;
}
@keyframes shimmer { to { background-position: 200% 0, 0 0; } }

.overall-label { font-weight: 600; color: var(--petrol-deep); margin-block: 0.5rem 0; }

.actions { margin-block-start: 1.8rem; display: flex; justify-content: flex-end; }

.done-note { font-weight: 600; margin-block-start: 1rem; padding: 0.8rem 1rem; border-radius: 10px; }
.done-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 9%, transparent); }
.done-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 9%, transparent); }

/* ---- Footer / privacy ---- */

.pagefoot {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem 1.5rem;
	align-items: center;
	justify-content: space-between;
	padding: 1rem clamp(1rem, 4vw, 2.5rem) 1.4rem;
	color: var(--ink-soft);
	font-size: 0.88rem;
}

.pagefoot-links {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem 1.5rem;
}

button.link {
	font-size: inherit;
	color: var(--petrol);
	background: none;
	border: none;
	text-decoration: underline;
	cursor: pointer;
	padding: 0;
}

.privacy-dialog {
	max-inline-size: 60ch;
	border: 1px solid var(--hairline);
	border-radius: var(--radius);
	padding: 2rem;
	font-family: var(--font-body);
	color: var(--ink);
	background: var(--card);
}
.privacy-dialog::backdrop { background: color-mix(in srgb, var(--ink) 55%, transparent); }
.privacy-dialog h2 { font-family: var(--font-display); color: var(--petrol-deep); margin-block-start: 0; }
.privacy-flag {
	font-weight: 600;
	color: var(--warn);
	background: color-mix(in srgb, var(--warn) 9%, transparent);
	padding: 0.5rem 0.8rem;
	border-radius: 8px;
}
.dialog-close {
	display: block;
	margin-block-start: 1.4rem;
	margin-inline: auto;
	font-size: 1rem;
	font-weight: 600;
	color: var(--petrol-deep);
	background: var(--card);
	border: 1.5px solid var(--petrol);
	border-radius: 10px;
	padding: 0.55rem 1.6rem;
	cursor: pointer;
	transition: background 0.15s ease;
}
.dialog-close:hover { background: var(--amber-soft); border-color: var(--amber); }

.licenses-dialog {
	max-block-size: min(85vh, 100%);
	overflow-y: auto;
}
.licenses-dialog h3 {
	font-family: var(--font-display);
	color: var(--petrol-deep);
	font-size: 1rem;
	margin-block: 1.3rem 0.4rem;
}
.license-table a { color: var(--petrol); }
.license-table {
	inline-size: 100%;
	border-collapse: collapse;
	font-size: 0.92rem;
}
.license-table th,
.license-table td {
	text-align: start;
	padding: 0.35rem 1rem 0.35rem 0;
	border-block-end: 1px solid var(--hairline);
}
.license-table th { color: var(--petrol-deep); }

.impressum-content h3 {
	font-family: var(--font-display);
	color: var(--petrol-deep);
	font-size: 1rem;
	margin-block: 1.1rem 0.25rem;
}
.impressum-content p { margin-block: 0 0.4rem; }

/* ---- Series preview lightbox ---- */

.preview-dialog {
	border: 1px solid var(--hairline);
	border-radius: var(--radius);
	padding: 1rem;
	background: var(--card);
	color: var(--ink);
	max-inline-size: min(92vw, 900px);
}
.preview-dialog::backdrop { background: color-mix(in srgb, var(--ink) 65%, transparent); }
.preview-dialog img {
	display: block;
	margin-inline: auto;
	min-inline-size: 16rem;
	min-block-size: 10rem;
	max-inline-size: 100%;
	max-block-size: 75vh;
	object-fit: contain;
	background: #000;
	border-radius: 6px;
}
.preview-caption { color: var(--ink-soft); text-align: center; margin-block: 0.6rem 0; }
.preview-dialog button { margin-block-start: 0.8rem; }

@media (max-width: 560px) {
	.file-row {
		grid-template-columns: auto 1fr auto auto;
		grid-template-areas: "kind name size remove" "status status status status" "bar bar bar bar";
	}
	.series-list { grid-template-columns: repeat(2, 1fr); }
	.secure-badge { display: none; }
	.actions { justify-content: stretch; }
	.actions .primary { inline-size: 100%; }
}
