/* Besucherspiegel – Design nach Vorbild des React-Dashboards */

:root {
  --background: 220 24% 98%;
  --foreground: 220 25% 12%;
  --card: 0 0% 100%;
  --primary: 217 91% 60%;
  --primary-foreground: 0 0% 100%;
  --muted: 220 16% 96%;
  --muted-foreground: 220 10% 48%;
  --border: 220 14% 93%;
  --success: 142 71% 45%;
  --warning: 38 92% 50%;
  --destructive: 0 84% 60%;
  --sidebar-bg: 220 25% 11%;
  --sidebar-fg: 220 14% 82%;
  --sidebar-accent: 220 20% 17%;
  --sidebar-border: 220 20% 19%;
  --shadow-card: 0 1px 2px hsl(220 25% 10% / .04), 0 8px 24px -14px hsl(220 25% 10% / .10);
  --radius: 12px;
}


[data-theme="dark"] {
  --background: 222 30% 8%;
  --foreground: 210 20% 92%;
  --card: 222 25% 12%;
  --muted: 222 20% 16%;
  --muted-foreground: 215 15% 55%;
  --border: 222 20% 18%;
  --sidebar-bg: 222 30% 6%;
  --sidebar-fg: 220 14% 75%;
  --sidebar-accent: 222 25% 12%;
  --sidebar-border: 222 20% 14%;
  --shadow-card: 0 1px 2px hsl(0 0% 0% / .3), 0 10px 30px -14px hsl(0 0% 0% / .5);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0 0 14px; font-weight: 600; letter-spacing: -.01em; }
.muted { color: hsl(var(--muted-foreground)); }
.small { font-size: 12.5px; }
.mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
code { font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace; font-size: .9em; }

/* ---------- Shell: Sidebar + Inhalt ---------- */
.shell { min-height: 100vh; display: flex; }

.sidebar {
  width: 240px; flex: 0 0 240px;
  background: hsl(var(--sidebar-bg));
  color: hsl(var(--sidebar-fg));
  border-right: 1px solid hsl(var(--sidebar-border));
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; font-size: 16px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: hsl(var(--primary)); color: #fff; font-size: 15px; font-weight: 700;
}
.brand .sub { display: block; font-size: 11px; font-weight: 500; color: hsl(var(--sidebar-fg)); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px; font-size: 14px; font-weight: 500;
  color: hsl(var(--sidebar-fg));
}
.nav a:hover { background: hsl(var(--sidebar-accent)); color: #fff; }
.nav a.active { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.nav .sep { margin-top: 10px; padding: 0 12px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: hsl(var(--muted-foreground)); }
.sidebar-foot { margin-top: auto; font-size: 11.5px; color: hsl(var(--muted-foreground)); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px; border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card)); position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.topbar .title-sm { font-weight: 600; font-size: 15px; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--foreground));
  cursor: pointer; padding: 0; font-size: 16px; line-height: 1;
}
.iconbtn:hover { background: hsl(var(--muted)); }
.burger { display: none; }

.wrap { padding: 22px; max-width: 1320px; width: 100%; margin: 0 auto; }
.page-head { margin-bottom: 18px; }
.foot { padding: 18px 22px 40px; color: hsl(var(--muted-foreground)); font-size: 12px; }

/* ---------- Karten & Raster ---------- */
.card {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
  box-shadow: var(--shadow-card);
}
.grid { display: grid; gap: 14px; }
.grid.kpi { grid-template-columns: repeat(4, 1fr); margin-bottom: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid.kpi .card { margin-bottom: 0; }

.kpi-label { color: hsl(var(--muted-foreground)); font-size: 12.5px; font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ---------- Tabellen ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid hsl(var(--border)); }
th {
  color: hsl(var(--muted-foreground)); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: hsl(var(--muted)); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: hsl(var(--muted)); color: hsl(var(--muted-foreground));
}
.badge.up { background: hsl(var(--success) / .12); color: hsl(var(--success)); }
.badge.down { background: hsl(var(--destructive) / .12); color: hsl(var(--destructive)); }
.badge.stable { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }

/* ---------- Diagramme ---------- */
.chart { width: 100%; height: 240px; min-height: 180px; display: block; }
.chart .grid { stroke: hsl(var(--border)); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart .line-1 { stroke: hsl(var(--primary)); }
.chart .line-2 { stroke: hsl(var(--success)); }
.chart .bar { fill: hsl(var(--primary)); opacity: .9; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.chart-legend .k1 { color: hsl(var(--primary)); font-weight: 600; }
.chart-legend .k2 { color: hsl(var(--success)); font-weight: 600; }
.chart-axis, .bar-labels { display: flex; justify-content: space-between; color: hsl(var(--muted-foreground)); font-size: 11px; margin-top: 6px; }
.bar-labels span { flex: 1; text-align: center; }

/* ---------- Heatmap ---------- */
.heat { overflow-x: auto; }
.heat-hours, .heat-row { display: grid; grid-template-columns: 32px repeat(24, minmax(11px, 1fr)); gap: 3px; align-items: center; }
.heat-hours { color: hsl(var(--muted-foreground)); font-size: 10px; margin-bottom: 5px; }
.heat-row { margin-bottom: 3px; }
.heat-day { color: hsl(var(--muted-foreground)); font-size: 11px; }
.heat-row i {
  display: block; height: 16px; border-radius: 4px;
  background: hsl(var(--muted));
  background-color: hsl(var(--primary) / var(--i, 0));
}

/* ---------- Formulare ---------- */
form.stack { display: grid; gap: 14px; max-width: 420px; }
label { font-size: 13px; color: hsl(var(--muted-foreground)); display: block; margin-bottom: 5px; font-weight: 500; }
input[type=text], input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--foreground));
  font: inherit; font-size: 15px;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid hsl(var(--primary)); outline-offset: 2px;
}
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 0; min-height: 42px;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font: inherit; font-weight: 600; cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.06); }
button.secondary, .btn.secondary {
  background: hsl(var(--card)); color: hsl(var(--foreground)); border: 1px solid hsl(var(--border));
}

.notice {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
  background: hsl(var(--primary) / .08); border: 1px solid hsl(var(--primary) / .25);
}
.notice.error { background: hsl(var(--destructive) / .08); border-color: hsl(var(--destructive) / .3); }
.notice.ok { background: hsl(var(--success) / .1); border-color: hsl(var(--success) / .3); }

pre.code {
  background: hsl(var(--muted)); border: 1px solid hsl(var(--border)); border-radius: 10px;
  padding: 14px; overflow-x: auto; font-size: 12.5px;
  font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

.log { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.log li { padding: 6px 0; border-bottom: 1px solid hsl(var(--border)); color: hsl(var(--muted-foreground)); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { margin-bottom: 4px; }
.filters select, .filters input { width: auto; min-width: 150px; }

tr.detail-row td { padding-top: 0; }
tr.detail-row summary { cursor: pointer; font-size: 12.5px; color: hsl(var(--primary)); font-weight: 500; }
.seq { margin: 10px 0 6px; padding-left: 18px; font-size: 12.5px; }
.seq li { padding: 3px 0; display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Login ---------- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: 16px;
  padding: 28px; width: 100%; max-width: 400px; box-shadow: var(--shadow-card);
}
.login-card .brand { color: hsl(var(--foreground)); margin-bottom: 18px; }

/* ---------- Mobil ---------- */
@media (max-width: 1024px) {
  .grid.kpi { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; height: 100vh; width: 262px;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax hsl(220 25% 10% / .5); }
  .burger { display: grid; }
  .wrap { padding: 16px; }
  .topbar { padding: 10px 14px; }
}

@media (max-width: 720px) {
  h1 { font-size: 21px; }
  .kpi-value { font-size: 23px; }
  .grid.kpi { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 14px; border-radius: 10px; }
  .table-scroll { margin: 0; padding: 0; overflow: visible; }

  /* Tabellen werden zu Karten – Labels setzt layout.php per JS */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr {
    border: 1px solid hsl(var(--border)); border-radius: 10px;
    padding: 6px 10px; margin-bottom: 10px; background: hsl(var(--card));
  }
  table.responsive tr:hover { background: hsl(var(--card)); }
  table.responsive td {
    border: 0; padding: 5px 0; display: flex; gap: 12px;
    align-items: baseline; justify-content: space-between; text-align: right;
  }
  table.responsive td::before {
    content: attr(data-label); flex: 0 0 auto; text-align: left;
    color: hsl(var(--muted-foreground)); font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  }
  table.responsive td:empty { display: none; }
  table.responsive td.num { text-align: right; }
  table.responsive tr.detail-row { padding: 0 10px 8px; margin-top: -10px; border-top: 0; border-radius: 0 0 10px 10px; }
  table.responsive tr.detail-row td { justify-content: flex-start; text-align: left; }
  table.responsive tr.detail-row td::before { content: ''; }
  .filters select, .filters input { min-width: 0; width: 100%; }
  .filters > div { flex: 1 1 140px; }
  .chart { height: 200px; }
}

/* ---------- Kompakte Liste (Übersicht) ---------- */
.card.slim { padding: 12px 14px; }
.filters.compact-filters { gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.filters.compact-filters select { padding: 4px 8px; font-size: 12.5px; }

table.compact { font-size: 12.5px; }
table.compact.visits { table-layout: fixed; }
table.compact th, table.compact td {
  padding: 4px 6px; border-bottom: 1px solid hsl(var(--border) / .55);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
table.compact th { font-size: 10px; letter-spacing: .05em; }
table.compact.visits td:first-child, table.compact.visits th:first-child { width: 64px; }
table.compact.visits td:nth-child(3), table.compact.visits th:nth-child(3) { width: 48px; }
table.compact.visits td:last-child, table.compact.visits th:last-child { width: 62px; }
table.compact .cell-page { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
table.compact .cell-page .path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.compact .cell-page .host { font-weight: 600; flex: 0 0 auto; }
table.compact .nowrap { white-space: nowrap; }

@media (max-width: 720px) {
  table.compact { font-size: 12px; }
  table.compact th, table.compact td { padding: 3px 4px; }
  table.compact.visits td:first-child, table.compact.visits th:first-child { width: 56px; }
  table.compact.visits td:nth-child(3), table.compact.visits th:nth-child(3) { width: 34px; }
  table.compact.visits td:last-child, table.compact.visits th:last-child { width: 52px; }
  table.compact .cell-page { gap: 4px; }
  table.compact .cell-page .host { font-size: 11.5px; }
  .card.slim { padding: 10px; }
}

/* ===== Auswertungs-Erweiterungen ===== */
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); }
.kpi-sub { margin-top: 6px; font-size: 12px; }

.live-strip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: 10px; padding: 9px 12px; margin-bottom: 14px; font-size: 13px;
}
.live-dot {
  width: 9px; height: 9px; border-radius: 50%; background: hsl(var(--success));
  box-shadow: 0 0 0 0 hsl(var(--success) / .6); animation: ds-pulse 2s infinite;
}
@keyframes ds-pulse {
  70% { box-shadow: 0 0 0 8px hsl(var(--success) / 0); }
  100% { box-shadow: 0 0 0 0 hsl(var(--success) / 0); }
}

.card.insight { margin-bottom: 0; font-size: 13px; border-left: 3px solid hsl(var(--muted-foreground) / .4); }
.card.insight.up { border-left-color: hsl(var(--success)); }
.card.insight.down { border-left-color: hsl(var(--destructive)); }

.hbars { display: flex; flex-direction: column; gap: 7px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 1.4fr) 2fr auto; gap: 10px; align-items: center; font-size: 12.5px; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: hsl(var(--muted)); border-radius: 999px; height: 8px; overflow: hidden; }
.hbar-track i { display: block; height: 100%; border-radius: 999px; background: hsl(var(--primary)); }
.hbar-value { white-space: nowrap; font-variant-numeric: tabular-nums; }

.small-btn { padding: 4px 9px; font-size: 12px; float: right; }
.filter-search { min-width: 150px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: hsl(var(--muted-foreground)); }
.inline-check input { width: auto; margin: 0; }

@media (max-width: 640px) {
  .hbar { grid-template-columns: 1fr auto; }
  .hbar-track { grid-column: 1 / -1; }
  .small-btn { float: none; display: inline-block; margin-top: 6px; }
}
