/* ==========================================================================
   Wiesnwecker Dashboard – Styles
   Farb-Rollen als Custom Properties; Dark Mode folgt dem System
   (prefers-color-scheme) mit eigens abgestimmten Werten.
   ========================================================================== */

:root {
  /* Flächen & Text */
  --page: #f9f9f7;
  --page-glass: rgba(249, 249, 247, .88);
  --surface: #fcfcfb;
  --pre-bg: #f4f3f0;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --ring: rgba(11, 11, 11, .10);
  --shadow: 0 1px 2px rgba(11, 11, 11, .05);

  /* Statusfarben (fest reserviert) + weiche Tönungen für Flächen */
  --ok: #0ca30c;        --ok-soft: #dff1de;
  --err: #d03b3b;       --err-soft: #f7e5e4;
  --gray: #898781;      --gray-soft: #eeeeec;

  /* Interaktions-Akzent (Buttons, Fokus, Countdown-Ring) */
  --accent: #2a78d6;
  --demo: #4a3aa7;      --demo-soft: #e6e4f1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --page-glass: rgba(13, 13, 13, .85);
    --surface: #1a1a19;
    --pre-bg: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --ring: rgba(255, 255, 255, .10);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);

    --ok: #0ca30c;      --ok-soft: #182a17;
    --err: #d03b3b;     --err-soft: #301e1d;
    --gray: #898781;    --gray-soft: #272725;

    --accent: #3987e5;
    --demo: #9085e9;    --demo-soft: #282632;
  }
}

/* --------------------------------------------------------------- Grundlagen */

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 8px;
}

main, .topbar-inner, .foot {
  max-width: 1160px;
  margin-inline: auto;
  padding-inline: clamp(16px, 3vw, 28px);
}

a { color: inherit; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.hidden { display: none !important; }

svg { display: block; }

.icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ------------------------------------------------------------------ Topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--page-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hairline);
}

.topbar-inner,
.topbar {                 /* topbar selbst als Flex-Container (ohne Wrapper) */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar {
  padding: 10px clamp(16px, 3vw, 28px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo { font-size: 28px; line-height: 1; }

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.2;
}

.tagline {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  min-width: 0;
  flex-wrap: wrap;
}

.updated {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Chips (Zeitfenster, Demo) */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-2);
  white-space: nowrap;
}

.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.chip-active .dot { background: var(--ok); }

.chip-demo {
  background: var(--demo-soft);
  border-color: transparent;
}
.chip-demo::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--demo);
}

/* Aktualisieren-Button mit Countdown-Ring */
.refresh-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  flex: none;
}

.refresh-btn:hover { border-color: var(--muted); }
.refresh-btn:active { transform: scale(.96); }

.ring {
  position: absolute;
  inset: 2px;
  width: auto;
  height: auto;
}

.ring-track,
.ring-fill {
  fill: none;
  stroke-width: 3;
}

.ring-track { stroke: var(--hairline); }

.ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 100.53;   /* 2 * PI * 16 */
  stroke-dashoffset: 0;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset 1s linear;
}

.refresh-icon {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.refresh-btn.busy .refresh-icon { animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- Verbindungsbanner */

.banner {
  margin: 14px 0 0;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--err-soft);
  border: 1px solid var(--ring);
  border-left: 4px solid var(--err);
  border-radius: 10px;
  font-size: 13px;
}

.banner .icon { color: var(--err); }

main .noscript,
.noscript {
  margin: 16px 0 0;
  padding: 10px 14px;
  background: var(--gray-soft);
  border-radius: 10px;
  font-size: 13px;
}

/* ------------------------------------------------------------- Gesamtstatus */

.summary {
  margin-top: 18px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px 28px;
  flex-wrap: wrap;
}

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.hero-text { min-width: 0; }

.hero-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--gray-soft);
  color: var(--gray);
  display: grid;
  place-items: center;
  flex: none;
}

.hero-icon .icon { width: 24px; height: 24px; stroke-width: 2.2; }

.sum-green .hero-icon { background: var(--ok-soft); color: var(--ok); }
.sum-red   .hero-icon { background: var(--err-soft); color: var(--err); }
.sum-gray  .hero-icon { background: var(--gray-soft); color: var(--gray); }

.hero-msg {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.005em;
}

.hero-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

/* Zähler-Kacheln: Wert + Label mit Status-Punkt (nie Farbe allein) */
.tiles {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  row-gap: 10px;
}

.tile {
  padding: 2px 22px;
  border-left: 1px solid var(--hairline);
}

.tile:first-child { border-left: 0; padding-left: 0; }
.tile:last-child { padding-right: 0; }

.tile-value {
  font-size: 28px;
  font-weight: 650;
  line-height: 1.15;
}

.tile.zero .tile-value { color: var(--muted); font-weight: 550; }

.tile-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}

.tile-label .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.dot-green { background: var(--ok); }
.dot-red   { background: var(--err); }
.dot-gray  { background: var(--gray); }

/* ---------------------------------------------------------------- Kartengrid */

.grid {
  margin-top: 16px;
  display: grid;
  /* min(330px, 100%): auch auf sehr schmalen Displays kein Overflow */
  grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr));
  gap: 14px;
}

.card {
  --sc: var(--gray);
  --sc-soft: var(--gray-soft);
  background: var(--surface);
  border: 1px solid var(--ring);
  border-left: 4px solid var(--sc);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 15px 16px 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
}

.st-ok      { --sc: var(--ok);  --sc-soft: var(--ok-soft); }
.st-error,
.st-stale   { --sc: var(--err); --sc-soft: var(--err-soft); }
.st-paused,
.st-unknown { --sc: var(--gray); --sc-soft: var(--gray-soft); }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-head h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -.005em;
}

.family {
  flex: none;
  margin-top: 1px;
  padding: 2px 7px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--muted);
  cursor: help;
}

.statusline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Status-Pill: getönte Fläche + farbiges Icon + Wort (Icon+Text, nie Farbe allein) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--sc-soft);
  font-size: 12.5px;
  font-weight: 650;
}

.pill .icon { color: var(--sc); }

.st-error .pill .icon,
.st-stale .pill .icon { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

.hit-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--ok-soft);
  font-size: 12.5px;
  font-weight: 600;
}

.hit-badge .icon { color: var(--ok); width: 13px; height: 13px; }

.status-text {
  margin: 0;
  font-size: 13px;
  color: var(--ink-2);
}

.meta {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-2);
  flex-wrap: wrap;
}

.meta .icon { width: 13px; height: 13px; color: var(--muted); }

.meta b { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }

.meta .src { color: var(--muted); cursor: help; }

/* Fehlerbox */
.error-box {
  display: flex;
  gap: 8px;
  padding: 9px 11px;
  min-width: 0;
  background: var(--err-soft);
  border-radius: 9px;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.error-box .icon { color: var(--err); margin-top: 2px; }

.error-box .err-text {
  flex: 1 1 auto;
  min-width: 0;              /* darf im Flex-Kontext schrumpfen -> Umbruch */
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Aufklappbarer Lauf-Block */
.logblock {
  margin-top: auto;           /* klebt am Kartenende, Karten gleich hoch */
  border-top: 1px solid var(--hairline);
  padding-top: 9px;
}

.logblock summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--ink-2);
  user-select: none;
}

.logblock summary::-webkit-details-marker { display: none; }
.logblock summary:hover { color: var(--ink); }

.logblock .chev {
  width: 12px;
  height: 12px;
  transition: transform .15s ease;
}

.logblock[open] .chev { transform: rotate(90deg); }

.logname {
  margin-left: auto;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
}

.logblock pre {
  margin: 9px 0 0;
  padding: 10px 12px;
  background: var(--pre-bg);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 280px;
  overflow: auto;
}

.logpath {
  margin: 7px 0 0;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
  user-select: all;           /* ein Klick markiert den ganzen Pfad */
}

/* ------------------------------------------------------------------- Footer */

.foot {
  margin-top: 26px;
  padding-bottom: 22px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.8;
}

.foot a { text-decoration: underline dotted; text-underline-offset: 2px; }

.foot .sep { margin: 0 7px; opacity: .6; }

/* ---------------------------------------------------------------- Skeletons */

.skeleton,
.skeleton-card {
  background: linear-gradient(100deg,
    var(--surface) 35%, var(--pre-bg) 50%, var(--surface) 65%);
  background-size: 220% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 120% 0; }
  to   { background-position: -120% 0; }
}

.summary.is-loading .hero-icon { color: transparent; }

.skeleton-text {
  border-radius: 6px;
  min-width: 210px;
}

.skeleton-card {
  min-height: 158px;
  border-left-color: var(--hairline);
}

/* --------------------------------------------------------------- Responsive */

@media (max-width: 640px) {
  .updated { display: none; }
  .tagline { display: none; }
  .summary { padding: 14px 16px; }
  .hero-msg { font-size: 16px; }
  .tiles { width: 100%; justify-content: space-between; }
  .tile { padding: 2px 14px; }
  .card { padding: 13px 14px 11px; }
}

/* -------------------------------------------------- Reduzierte Bewegung */

@media (prefers-reduced-motion: reduce) {
  .skeleton, .skeleton-card,
  .st-error .pill .icon,
  .st-stale .pill .icon,
  .refresh-btn.busy .refresh-icon { animation: none; }
  .ring-fill { transition: none; }
  .logblock .chev { transition: none; }
}
