/* Stats4U - Basis-Styles
   Vorher in drei Inline-<style>-Bloecken verteilt (renderHeader, showFrontend,
   showLiveStats), teils doppelt. Extern wird die Datei einmal geladen und
   dann gecacht (Cache-Control per .htaccess, Versionierung ueber ?v=mtime). */

:root {
  --primary: #3b82f6;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --accent: #4be3ac;
}

body {
  /* Statt Google Fonts (Inter): System-Stack, kein Drittanbieter-Request. */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  line-height: 1.6;
}

.container { max-width: 1000px; margin: 0 auto; padding: 40px 20px; }
header { text-align: center; margin-bottom: 50px; }
h1 { font-size: 2.5rem; margin-bottom: 10px; color: var(--primary); }
p.subtitle { font-size: 1.1rem; color: var(--text-light); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 30px; }

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  transition: transform 0.2s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }

.preview-box {
  background: #f1f5f9;
  padding: 30px;
  text-align: center;
  border-radius: 8px;
  margin-bottom: 20px;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-box img { max-width: 100%; height: auto; }

pre { background: #1e293b; color: #f8f8f2; padding: 15px; border-radius: 8px; overflow-x: auto; font-size: 0.85rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.stats-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 30px; border-bottom: 1px solid var(--border); padding-bottom: 20px;
  flex-wrap: wrap; gap: 10px;
}
canvas { max-width: 100%; }

/* --- Kopfzeile / Sprachwahl ------------------------------------------------
   Der Header nutzt .lang-switcher; renderHeader() definierte frueher
   .lang-switch, das nirgends im Markup vorkam - die Regeln griffen nie. */
.main-header {
  margin-top: 16px; margin-bottom: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px; flex-wrap: wrap; gap: 10px;
}
.lang-switcher {
  margin-left: auto; display: flex; gap: 8px;
  flex-wrap: wrap; justify-content: flex-end;
}
.lang-switcher a {
  text-decoration: none; padding: 5px 8px;
  border: 1px solid #ddd; border-radius: 4px;
  font-size: 0.8rem; color: #333;
}
.lang-switcher a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (max-width: 400px) {
  .main-header { flex-direction: column; text-align: center; }
}

/* --- Startseite: 3-Schritt-Flow -------------------------------------------
   Vorher standen 111 Vorschauen flach nebeneinander, jede mit eigenem
   Code-Block darunter. Jetzt: nach Art gruppierte Kacheln, eine Auswahl,
   ein Code-Block. */
.step { margin: 0 0 48px; }
.step h2 {
  display: flex; align-items: center; gap: 12px;
  font-size: 1.4rem; margin: 0 0 6px;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: 0 0 32px;
  border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 1rem; font-weight: 700;
}

.cat-title {
  font-size: 1rem; font-weight: 600; margin: 28px 0 12px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.cat-hint { display: block; font-weight: 400; font-size: 0.85rem; color: var(--text-light); margin-top: 2px; }

.style-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px; margin-bottom: 8px;
}

/* Kacheln sind <button>, damit sie per Tastatur bedienbar sind. */
.style-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--card); border: 2px solid var(--border); border-radius: 10px;
  padding: 12px; cursor: pointer; font: inherit; color: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.style-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.style-card:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.style-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.18); }
.style-card .preview-box { margin: 0; padding: 12px; width: 100%; box-sizing: border-box; }
.style-card .style-id { font-size: 0.75rem; color: var(--text-light); }

.more-styles > summary {
  cursor: pointer; padding: 10px 0; color: var(--primary); font-weight: 500;
}
.more-styles[open] > summary { margin-bottom: 12px; }

.option-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.option-row label { font-weight: 500; }
.option-row input[type="number"] {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font: inherit; width: 160px;
}
.private-link { color: var(--primary); word-break: break-all; margin: 4px 0 0; }
.selected-label { color: var(--text-light); font-size: 0.9rem; margin: 0 0 8px; }

.copy-btn {
  background: var(--primary); color: #fff; border: 0; border-radius: 6px;
  padding: 10px 18px; font: inherit; font-weight: 500; cursor: pointer;
}
.copy-btn:hover { filter: brightness(1.08); }
.copy-status { margin-left: 10px; color: #10b981; font-weight: 500; }

/* --- Statistik-Seite ------------------------------------------------------- */
.summary-boxes { display: flex; gap: 20px; margin-bottom: 30px; }
.summary-box {
  flex: 1; background: var(--card); padding: 20px; border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05); text-align: center;
  border-bottom: 4px solid var(--primary);
}
.summary-box h3 { margin: 0; font-size: 1rem; color: var(--text-light); font-weight: 500; }
.summary-box p { margin: 10px 0 0; font-size: 2rem; font-weight: 700; color: var(--text); }
.summary-box.green { border-bottom-color: #10b981; }

.geo-section { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 40px; }
.geo-list { list-style: none; padding: 0; margin: 0; }
.geo-list li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 15px; }
.geo-list li:last-child { border-bottom: none; }
.geo-list li span.flag { font-weight: bold; color: var(--primary); }

/* --- Verlaufskurve als Inline-SVG ------------------------------------------
   Ersetzt Chart.js (208 KB roh / ~70 KB gzip). Die Farben kommen aus den
   Token, das Diagramm macht Dark Mode und Markenfarben also automatisch mit -
   was Chart.js mit hartkodierten Farben nicht konnte. */
.chart-card { margin-bottom: 30px; }
svg.trend { display: block; width: 100%; height: 260px; }
svg.trend .grid { stroke: var(--border); stroke-width: 1; }
svg.trend .tick { fill: var(--text-light); font-size: 11px; font-family: inherit; }
svg.trend .area { fill: var(--primary); opacity: 0.10; stroke: none; }
svg.trend .s1   { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; }
svg.trend .s2   { fill: none; stroke: #10b981;        stroke-width: 2; stroke-linejoin: round; }
svg.trend .hit  { fill: transparent; }
svg.trend .hit:hover { fill: var(--primary); opacity: 0.07; }

.chart-legend { display: flex; gap: 18px; font-size: 0.85rem; color: var(--text-light); margin-bottom: 6px; }
.chart-legend span::before {
  content: ""; display: inline-block; width: 10px; height: 10px;
  border-radius: 2px; margin-right: 6px; vertical-align: baseline;
}
.chart-legend .k1::before { background: var(--primary); }
.chart-legend .k2::before { background: #10b981; }

/* Anteilsbalken in der Listenzeile - ersetzt drei Tortendiagramme, die
   dasselbe zeigten wie die Liste daneben. 14 Byte pro Zeile. */
.geo-list.share li { position: relative; }
.geo-list.share li::before {
  content: ""; position: absolute; left: 0; bottom: 0;
  width: var(--p, 0%); height: 2px; background: var(--primary); opacity: 0.35;
}
.geo-list em { font-style: normal; color: var(--text-light); margin-left: 6px; }
h3.sec { margin-top: 0; color: var(--primary); font-size: 1rem; }

.quick-stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px; margin-bottom: 30px;
}
.stat-card {
  background: var(--card); padding: 20px; border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05); text-align: center;
}
.stat-card h4 { margin: 0 0 10px 0; color: #666; font-size: 0.9rem; }
.stat-card .value { font-size: 1.8rem; font-weight: bold; color: #333; margin-bottom: 5px; }
.stat-card .desc { font-size: 0.8rem; color: #999; }

@media (max-width: 768px) {
  .geo-section { grid-template-columns: 1fr; }
  .summary-boxes { flex-direction: column; }
}

/* Der Aufklapper fuer die Klassiker von 2006. Bewusst deutlicher als die
   Untergruppen darin - er trennt "neu" von "gewachsen". */
.more-styles.legacy > summary {
  margin-top: 8px; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  font-weight: 600; color: var(--text);
}
.more-styles.legacy > summary:hover { border-color: var(--primary); }
.more-styles.legacy[open] > summary { margin-bottom: 16px; }

/* --- Wizard: Form und Farben frei waehlen ----------------------------------
   Die Vorschau kommt vom Server (unter 1 KB pro SVG). Eine eigene
   Zeichenlogik in JS waere eine zweite Wahrheit neben SvgCounterStyles. */
#wizard {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px; margin: 6px 0 22px;
}
.wiz-preview {
  display: flex; align-items: center; justify-content: center;
  min-height: 84px; padding: 16px; margin-bottom: 16px;
  border-radius: 8px;
  /* Schachbrett: zeigt, wo der Zaehler durchscheinend ist (Form "Ghost") */
  background-image:
    linear-gradient(45deg, #eef2f5 25%, transparent 25%, transparent 75%, #eef2f5 75%),
    linear-gradient(45deg, #eef2f5 25%, transparent 25%, transparent 75%, #eef2f5 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
  background-color: #fff;
}
.wiz-preview img { max-width: 100%; height: auto; }

.wiz-row { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.wiz-lab { flex: 0 0 96px; font-size: 0.85rem; color: var(--text-light); padding-top: 6px; }

.wiz-forms { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.wiz-chip {
  font: inherit; font-size: 0.82rem; cursor: pointer;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.wiz-chip:hover { border-color: var(--primary); }
.wiz-chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.wiz-pals { display: flex; flex-wrap: wrap; gap: 7px; flex: 1; }
.wiz-pal {
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border) inset;
}
.wiz-pal.on { border-color: var(--text); }
.wiz-pal:focus-visible, .wiz-chip:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.wiz-row input[type="color"] {
  width: 44px; height: 30px; padding: 0; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: none;
}
.wiz-dark { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-light); }

@media (max-width: 560px) { .wiz-lab { flex-basis: 100%; padding-top: 0; } }
.wiz-text {
  flex: 1; min-width: 180px; max-width: 320px;
  padding: 6px 10px; font: inherit; font-size: 0.88rem;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text);
}
.wiz-text:focus-visible { outline: 3px solid var(--primary); outline-offset: 1px; }

/* Klassikmodus: Vorlagengalerie und Hinweis */
.wiz-note { flex-basis: 100%; margin: 0 0 12px; font-size: 0.82rem; color: var(--text-light); }
.wiz-tpls { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.wiz-tpl {
  width: 54px; height: 34px; border-radius: 6px; cursor: pointer;
  background-size: cover; background-position: center;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border) inset;
}
.wiz-tpl.on { border-color: var(--primary); }
.wiz-tpl:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
select.wiz-text { max-width: 240px; }

/* --- Live-Leiste ------------------------------------------------------------
   Bleibt oben stehen und sagt, wie frisch die Zahlen sind. Ohne diese Angabe
   waere unklar, ob sich gerade nichts tut oder ob die Anzeige haengt. */
.livebar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 20px;
  background: var(--card); border-bottom: 1px solid var(--border);
  font-size: 0.85rem; color: var(--text-light);
}
.livebar strong { color: #10b981; letter-spacing: 0.08em; font-size: 0.78rem; }
.livebar .live-online b { color: var(--text); font-size: 1rem; }
.livebar .live-age { margin-left: auto; font-variant-numeric: tabular-nums; }

.livedot {
  width: 9px; height: 9px; border-radius: 50%; background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,0.6);
  animation: s4upulse 2s infinite;
}
@keyframes s4upulse {
  0%   { box-shadow: 0 0 0 0 rgba(16,185,129,0.55); }
  70%  { box-shadow: 0 0 0 9px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
/* Bei abgeschalteter Bewegung nur der Punkt, kein Pulsieren. */
@media (prefers-reduced-motion: reduce) { .livedot { animation: none; } }

/* Antwort ausgeblieben: Punkt und Beschriftung gehen auf grau, damit niemand
   veraltete Zahlen fuer aktuelle haelt. */
.livebar.stale .livedot { background: #94a3b8; animation: none; box-shadow: none; }
.livebar.stale strong   { color: #94a3b8; }

/* --- Wer ist gerade da ------------------------------------------------------ */
.geo-list.who li { align-items: center; }
.geo-list.who img { vertical-align: -1px; }
.muted { color: var(--text-light); font-size: 0.88rem; }

/* --- Tagesverlauf: 24 Balken ------------------------------------------------ */
.hours { display: flex; align-items: flex-end; gap: 3px; height: 96px; margin-top: 6px; }
.hours .hbar {
  flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: center; height: 100%; gap: 4px;
}
.hours .hbar i {
  display: block; width: 100%; min-height: 2px; border-radius: 2px 2px 0 0;
  background: var(--primary); opacity: 0.75; transition: height 0.4s ease;
}
.hours .hbar.now i { opacity: 1; background: #10b981; }
.hours .hbar em { font-style: normal; font-size: 9px; color: var(--text-light); }
@media (max-width: 560px) { .hours .hbar em { display: none; } }
@media (prefers-reduced-motion: reduce) { .hours .hbar i { transition: none; } }

/* Datumsangabe in einer Kennzahl-Box: die Ziffern einer Jahreszahl brauchen
   nicht dieselbe Groesse wie eine Besucherzahl. */
.summary-box p.small { font-size: 1.35rem; }

/* Wizard: mehr Werte als in die Tafel passen. Die uebrigen Marken werden matt,
   damit erkennbar ist, dass ein Klick dort nichts bewirkt. */
.wiz-chip.off { opacity: 0.4; cursor: not-allowed; }
