/*
 * Dunkles Farbschema. Zentrale Stelle fuer alle dunklen Werte.
 *
 * Die uebrigen Stylesheets verwenden var(--tb-..., <helle Farbe>). Hell sind die
 * Variablen nicht definiert, dort greift immer der Fallback. Neue Farben daher
 * nach demselben Muster schreiben und die dunkle Variante hier ergaenzen.
 * data-theme setzt templates/theme.inc.php noch vor dem ersten Zeichnen.
 * @media screen: gedruckt wird immer hell.
 */
@media screen {

html[data-theme="dark"] {
	color-scheme: dark;

	/* Flaechen (neutral bis leicht kuehl, bewusst ohne Braun/Ocker) */
	--tb-page: #121316;
	--tb-surface: #1b1d21;
	--tb-surface-alt: #202327;
	--tb-subtle: #262a30;
	--tb-hover: #30343b;
	--tb-control: #363b43;
	--tb-control-hover: #474d57;
	--tb-highlight: #2b3038;
	--tb-highlight-strong: #363d47;
	--tb-tint: #23262c;
	--tb-segment-active: #4a515c;

	/* Schrift */
	--tb-text: #e6e8eb;
	--tb-text-2: #c3c7ce;
	--tb-text-muted: #9aa0a8;
	--tb-text-faint: #838a94;
	--tb-text-disabled: #596069;

	/* Rahmen und Schatten */
	--tb-border: #3a3f47;
	--tb-border-soft: #2e323a;
	--tb-glow: rgba(0, 0, 0, 0.6);
	--tb-blur-shadow: rgba(230, 232, 235, 0.6);

	/* Akzent und Status */
	--tb-accent-text: #ffad33;
	--tb-on-accent: #191919;
	--tb-active-bg: #ffad33;
	--tb-active-text: #191919;
	--tb-badge-bg: #191919;
	--tb-badge-text: #ffad33;
	--tb-success: #4cc27a;
	--tb-success-bg: #17331f;
	--tb-danger: #f07070;
	--tb-danger-bg: #3a2124;
}

/* Browser-Standardfarben, die in den Stylesheets nirgends gesetzt sind */
html[data-theme="dark"] body {
	background-color: var(--tb-page);
	color: var(--tb-text);
}

html[data-theme="dark"] dialog {
	background-color: var(--tb-surface);
	color: var(--tb-text);
}

/* Formularfelder ohne eigene Hintergrundfarbe (:where, damit spezifischere Regeln gewinnen) */
html[data-theme="dark"] :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="submit"], [type="button"]), textarea, select:not(.languageSelect)) {
	background-color: var(--tb-surface);
}

/* dunkle Schrift auf orangem Grund (Schriftfarbe sonst geerbt) */
html[data-theme="dark"] .header-notice,
html[data-theme="dark"] .top-message:not(.error),
html[data-theme="dark"] .btn-active {
	color: #191919;
}

/* Werbe- und Fremd-iframes: ohne passendes color-scheme malt der Browser einen
   deckend weissen Hintergrund hinter sonst transparente Inhalte */
html[data-theme="dark"] iframe {
	color-scheme: light;
}

/* Der eingebundene Spreadshop (merchandising) bringt nur helle Farben mit */
html[data-theme="dark"] #myShop {
	background-color: #fff;
}

/* Dunkle Karte: nur die Kacheln werden umgefaerbt, Marker und Popups liegen auf
   eigenen Ebenen. invert() kehrt die Helligkeit um, hue-rotate() holt die Farbtoene
   zurueck (Wasser blau, Parks gruen); saturate() daempft die braeunlich wirkenden
   gelb-orangen Nebenstrassen */
html[data-theme="dark"] .leaflet-tile-pane {
	filter: invert(1) hue-rotate(180deg) brightness(1.2) contrast(0.85) saturate(0.7);
}

/* Grund hinter noch nicht geladenen Kacheln (leaflet.css wird spaeter geladen) */
html[data-theme="dark"] .leaflet-container {
	background-color: #1b1d21;
}

/* Popups der Marker (leaflet.css wird spaeter geladen, die Selektoren hier sind spezifischer).
   Der erste Schatten ist ein 1px-Rand, damit sie sich von der dunklen Karte abheben */
html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip {
	background: var(--tb-subtle);
	color: var(--tb-text);
	box-shadow: 0 0 0 1px var(--tb-border), 0 3px 14px rgba(0, 0, 0, 0.6);
}

html[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button {
	color: var(--tb-text-muted);
}

html[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button:hover,
html[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button:focus {
	color: var(--tb-text);
}

/* Bedienelemente der Karte (Zoom, Quellenangabe) und Shop bleiben hell: dort gelten wieder die hellen Fallbacks */
html[data-theme="dark"] .leaflet-control-container,
html[data-theme="dark"] #myShop {
	color-scheme: light;
	color: #333;
	--tb-page: initial;
	--tb-surface: initial;
	--tb-surface-alt: initial;
	--tb-subtle: initial;
	--tb-hover: initial;
	--tb-control: initial;
	--tb-control-hover: initial;
	--tb-highlight: initial;
	--tb-highlight-strong: initial;
	--tb-tint: initial;
	--tb-text: initial;
	--tb-text-2: initial;
	--tb-text-muted: initial;
	--tb-text-faint: initial;
	--tb-border: initial;
	--tb-border-soft: initial;
	--tb-accent-text: initial;
	--tb-blur-shadow: initial;
}

/* SVG-Grafiken mit fest eingetragener Strichfarbe (Statistik, Databroker) */
html[data-theme="dark"] .databroker-promo-icon,
html[data-theme="dark"] .static-content svg[stroke="#000"] {
	stroke: var(--tb-text-2);
}

/* Databroker-Seiten (pages/get-databroker*.php, je Sprache eine Datei): Farben
   stehen dort inline bzw. in <style>, deshalb hier zentral ueberschrieben */
html[data-theme="dark"] .info-box[style],
html[data-theme="dark"] .halfpage-box[style]:not(.stat-box) {
	background-color: var(--tb-subtle) !important;
}

html[data-theme="dark"] .content:has(.actionbutton) .actionbutton {
	background-color: var(--tb-hover);
}

html[data-theme="dark"] .content:has(.actionbutton) :is(th, td) {
	border-color: var(--tb-border);
}

html[data-theme="dark"] .content:has(.actionbutton) :is(tbody tr:first-child th, tr:last-child td) {
	background-color: var(--tb-hover);
}

html[data-theme="dark"] .static-content [style*="color:#d9d9d9"] {
	color: var(--tb-text-faint) !important;
}

/* Karten der Markenseiten: Schatten allein ist auf dunklem Grund unsichtbar */
html[data-theme="dark"] :is(.brand-overview-card, .brand-stat-card, .brand-content) {
	border: 1px solid var(--tb-border-soft);
}

/* dunkle Logos auf transparentem Grund brauchen eine helle Unterlage */
html[data-theme="dark"] .brand-logo,
html[data-theme="dark"] .brand-overview-logo {
	background: #e6e8eb;
	border-radius: 8px;
	padding: 6px;
	box-sizing: border-box;
}

html[data-theme="dark"] .mtsk-price-logo {
	background: #e6e8eb;
	border-radius: 3px;
	padding: 1px 2px;
	box-sizing: border-box;
}

}
