/* Farben und Maße angelehnt an jwdiva (react-app/src/index.css), helles Theme gedämpft statt Reinweiß */
:root {
	--bg: #dde0e6;
	--card-bg: #eceef2;
	--text: #262a35;
	--text-muted: #5c6170;
	--border: #c6cad3;
	--primary: #4a66e8;
	--primary-hover: #3b58e0;
	--primary-text: #ffffff;
	--primary-soft: rgba(74, 102, 232, 0.13);
	--success-bg: #dcefe3;
	--success-border: #a9d4b8;
	--success-text: #1d6b3d;
	--error-bg: #f5e1e0;
	--error-border: #e5b3b0;
	--error-text: #b0352a;
	--shadow: 0 2px 12px rgba(30, 35, 50, 0.08);
	--radius: 10px;
	--gutter: 16px;
	color-scheme: light;
}

/* js/theme.js setzt data-theme nach eigener Wahl oder Systemeinstellung */
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #171a21;
	--card-bg: #1b2838;
	--text: #c6d4df;
	--text-muted: #8f98a0;
	--border: #2a475e;
	--primary-hover: #6b85ff;
	--primary-soft: rgba(102, 192, 244, 0.14);
	--success-bg: #16291f;
	--success-border: #24563a;
	--success-text: #6fd59a;
	--error-bg: #2a1a1a;
	--error-border: #5a2a2a;
	--error-text: #ff6b6b;
	--shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
}

*, *::before, *::after {
	box-sizing: border-box;
}

[hidden] {
	display: none !important;
}

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body {
	margin: 0;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', Arial, sans-serif;
	font-size: 16px;
	line-height: 1.5;
	background: var(--bg);
	color: var(--text);
	-webkit-font-smoothing: antialiased;
}

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

h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }

img {
	display: block;
	max-width: 100%;
}

/* --- Kopfzeile ---------------------------------------------------------- */

.topbar {
	position: sticky;
	top: 0;
	z-index: 5;
	background: var(--card-bg);
	border-bottom: 1px solid var(--border);
	padding-top: env(safe-area-inset-top);
}

.topbar-inner {
	display: flex;
	align-items: center;
	gap: 12px;
	max-width: 1000px;
	margin: 0 auto;
	padding: 10px var(--gutter);
	min-height: 56px;
}

.brand {
	font-weight: 700;
	letter-spacing: 0.04em;
	color: var(--primary);
}

.who {
	color: var(--text-muted);
	font-size: 0.9rem;
}

.theme-toggle {
	margin-left: auto;
}

.theme-toggle .icon-sun,
[data-theme="dark"] .theme-toggle .icon-moon {
	display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
	display: block;
}

/* --- Layout ------------------------------------------------------------- */

.wrap {
	display: grid;
	gap: var(--gutter);
	max-width: 1000px;
	margin: 0 auto;
	padding: var(--gutter) var(--gutter) calc(var(--gutter) + env(safe-area-inset-bottom));
}

.card {
	display: grid;
	gap: 14px;
	min-width: 0;
	padding: 18px var(--gutter);
	background: var(--card-bg);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.hint {
	margin: 0;
	color: var(--text-muted);
	font-size: 0.9rem;
}

/* --- Meldungen ---------------------------------------------------------- */

.alert {
	padding: 12px 14px;
	border-radius: var(--radius);
	border: 1px solid;
}

.alert-success {
	background: var(--success-bg);
	border-color: var(--success-border);
	color: var(--success-text);
}

.alert-danger {
	background: var(--error-bg);
	border-color: var(--error-border);
	color: var(--error-text);
}

/* --- Schaltflächen ------------------------------------------------------ */

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 44px;
	padding: 0 20px;
	border: 1px solid transparent;
	border-radius: var(--radius);
	font: inherit;
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
	transition: background 0.2s, border-color 0.2s;
}

.btn:disabled {
	opacity: 0.6;
	cursor: progress;
}

.btn-primary {
	background: var(--primary);
	color: var(--primary-text);
}

.btn-primary:hover:not(:disabled) {
	background: var(--primary-hover);
}

.btn-ghost {
	background: transparent;
	border-color: var(--border);
	color: var(--text);
}

.btn-ghost:hover {
	border-color: var(--primary);
	color: var(--primary);
}

.btn-sm {
	min-height: 36px;
	padding: 0 14px;
	font-size: 0.9rem;
}

.btn-block {
	width: 100%;
}

.icon-btn {
	display: inline-grid;
	place-items: center;
	flex: none;
	width: 44px;
	height: 44px;
	border: 0;
	border-radius: var(--radius);
	background: transparent;
	color: var(--text-muted);
	cursor: pointer;
}

.icon-btn:hover {
	background: var(--primary-soft);
	color: var(--text);
}

.icon-btn.danger:hover {
	background: var(--error-bg);
	color: var(--error-text);
}

:focus-visible {
	outline: 3px solid var(--primary);
	outline-offset: 2px;
}

/* --- Anmeldung ---------------------------------------------------------- */

.login {
	width: 100%;
	max-width: 380px;
	margin: 8vh auto 0;
	gap: 18px;
}

.field {
	display: grid;
	gap: 6px;
	font-weight: 600;
	font-size: 0.9rem;
}

.field input {
	min-height: 48px;
	padding: 0 14px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	color: var(--text);
	font: inherit;
	font-weight: 400;
}

.field input:focus {
	outline: none;
	border-color: var(--primary);
	box-shadow: 0 0 0 3px var(--primary-soft);
}

/* --- Upload ------------------------------------------------------------- */

.upload {
	display: grid;
	gap: 12px;
}

.drop {
	position: relative;
	display: grid;
	justify-items: center;
	gap: 4px;
	padding: 22px 16px;
	border: 2px dashed var(--border);
	border-radius: var(--radius);
	text-align: center;
	cursor: pointer;
	transition: border-color 0.2s, background 0.2s;
}

.drop:hover,
.drop:focus-within,
.upload.has-file .drop {
	border-color: var(--primary);
	background: var(--primary-soft);
}

/* Unsichtbar über der ganzen Fläche: Antippen und Drag & Drop funktionieren nativ */
.drop input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	cursor: pointer;
}

.drop-icon {
	color: var(--primary);
}

.drop-title {
	font-weight: 600;
	overflow-wrap: anywhere;
}

.drop-hint {
	color: var(--text-muted);
	font-size: 0.85rem;
}

/* --- Dateiliste --------------------------------------------------------- */

.files summary {
	display: flex;
	align-items: center;
	gap: 10px;
	list-style: none;
	cursor: pointer;
}

.files summary::-webkit-details-marker {
	display: none;
}

.files summary::after {
	content: '';
	width: 10px;
	height: 10px;
	margin-left: 4px;
	border-right: 2px solid var(--text-muted);
	border-bottom: 2px solid var(--text-muted);
	transform: rotate(45deg) translateY(-3px);
	transition: transform 0.2s;
}

.files[open] summary::after {
	transform: rotate(-135deg) translateX(-3px);
}

.badge {
	margin-left: auto;
	padding: 2px 10px;
	border-radius: 999px;
	background: var(--primary-soft);
	color: var(--text-muted);
	font-size: 0.8rem;
	font-weight: 600;
}

.file-list {
	display: grid;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.file {
	display: flex;
	align-items: center;
	gap: 4px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.file-open {
	display: flex;
	align-items: center;
	gap: 12px;
	flex: 1;
	min-width: 0;
	padding: 8px;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.file-open img {
	flex: none;
	width: 44px;
	height: 60px;
	object-fit: cover;
	object-position: top;
	border: 1px solid var(--border);
	border-radius: 4px;
	background: #fff;
}

.file-text {
	display: grid;
	min-width: 0;
}

.file-name {
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.file-meta {
	color: var(--text-muted);
	font-size: 0.85rem;
}

.file form {
	margin: 0 4px 0 0;
}

.regenerate {
	margin-top: 4px;
}

/* --- Anzeigetafeln ------------------------------------------------------ */

.hosts {
	display: flex;
	gap: 8px;
	margin: 0 calc(-1 * var(--gutter));
	padding: 2px var(--gutter);
	overflow-x: auto;
	scrollbar-width: none;
}

.chip {
	flex: none;
	display: inline-flex;
	align-items: center;
	min-height: 40px;
	padding: 0 16px;
	border: 1px solid var(--border);
	border-radius: 999px;
	color: var(--text);
	text-decoration: none;
	font-weight: 600;
	font-size: 0.9rem;
}

.chip.is-active {
	background: var(--primary);
	border-color: var(--primary);
	color: var(--primary-text);
}

.board {
	display: grid;
	gap: 14px;
}

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

.slots-single {
	grid-template-columns: minmax(0, 260px);
}

.slot {
	position: relative;
	display: grid;
	gap: 8px;
	padding: 8px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	color: inherit;
	font: inherit;
	text-align: left;
	cursor: pointer;
	transition: border-color 0.2s, box-shadow 0.2s;
}

.slot:hover {
	border-color: var(--primary);
	box-shadow: 0 0 0 3px var(--primary-soft);
}

.slot img {
	width: 100%;
	aspect-ratio: 210 / 297;
	object-fit: contain;
	border-radius: 4px;
	background: #fff;
}

.slot-no {
	position: absolute;
	top: 14px;
	left: 14px;
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--primary);
	color: var(--primary-text);
	font-size: 0.85rem;
	font-weight: 700;
}

.slot-label {
	font-size: 0.85rem;
	overflow-wrap: anywhere;
}

/* Auf dem Handy klebt die Speichern-Leiste unten am Bildschirm */
.savebar {
	position: sticky;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 12px;
	margin: 0 calc(-1 * var(--gutter)) -18px;
	padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
	background: var(--card-bg);
	border-top: 1px solid var(--border);
	border-radius: 0 0 var(--radius) var(--radius);
}

.savebar .btn {
	flex: 1;
}

.dirty-note {
	display: none;
	color: var(--text-muted);
	font-size: 0.85rem;
}

.board.is-dirty .dirty-note {
	display: block;
}

/* --- Auswahl- und Ansichtsdialog ---------------------------------------- */

.sheet {
	width: 100%;
	max-width: 100%;
	height: 100%;
	max-height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	background: var(--card-bg);
	color: var(--text);
}

.sheet[open] {
	display: flex;
	flex-direction: column;
}

.sheet::backdrop {
	background: rgba(0, 0, 0, 0.55);
}

.sheet-head {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: calc(6px + env(safe-area-inset-top)) 6px 6px;
	border-bottom: 1px solid var(--border);
}

.sheet-head h3 {
	flex: 1;
	padding: 0 8px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sheet-body {
	flex: 1;
	overflow-y: auto;
	padding: var(--gutter) var(--gutter) calc(var(--gutter) + env(safe-area-inset-bottom));
	overscroll-behavior: contain;
}

.grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
	gap: 12px;
}

.tile {
	display: grid;
	align-content: start;
	gap: 6px;
	padding: 8px;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	color: inherit;
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.tile:hover {
	border-color: var(--primary);
	box-shadow: 0 0 0 3px var(--primary-soft);
}

.tile img {
	width: 100%;
	aspect-ratio: 210 / 297;
	object-fit: contain;
	border-radius: 4px;
	background: #fff;
}

.tile-label {
	font-size: 0.85rem;
	font-weight: 600;
	overflow-wrap: anywhere;
}

.tile-meta {
	color: var(--text-muted);
	font-size: 0.8rem;
}

.viewer {
	display: grid;
	gap: 20px;
	max-width: 760px;
	margin: 0 auto;
}

.viewer figure {
	margin: 0;
}

.viewer img {
	width: 100%;
	border: 1px solid var(--border);
	border-radius: 4px;
	background: #fff;
}

.viewer figcaption {
	margin-top: 6px;
	color: var(--text-muted);
	font-size: 0.85rem;
	text-align: center;
}

/* --- Größere Bildschirme ------------------------------------------------ */

@media (min-width: 640px) {
	:root {
		--gutter: 24px;
	}

	.slots {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.savebar {
		position: static;
		margin: 0;
		padding: 0;
		border: 0;
		background: none;
	}

	.savebar .btn {
		flex: none;
		min-width: 180px;
	}

	.file-list {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.sheet {
		width: min(920px, calc(100% - 48px));
		height: min(820px, calc(100% - 48px));
		margin: auto;
		border-radius: var(--radius);
		box-shadow: var(--shadow);
	}
}
