:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #141a26;
  --muted: #667085;
  --accent: #e8590c;
  --accent-strong: #c2410c;
  --accent-soft: #fff1e8;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --ok-soft: #ecfdf3;
  --ok: #067647;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --topbar: 56px;
  color-scheme: light;
}

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

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; margin-top: 20px; }
p { margin: 8px 0; }
a { color: var(--accent-strong); }
code {
  font: 12.5px/1.4 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  word-break: break-all;
}
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Formularelemente ---------- */

input, select, textarea, button { font: inherit; color: inherit; }

input:not([type="hidden"]), select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 89, 12, .15);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field > label, .field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field small { color: var(--muted); font-size: 12.5px; }
.field small.error, .has-error small.error { color: var(--danger); }
.has-error input, .has-error textarea { border-color: var(--danger); }

.stack { display: flex; flex-direction: column; gap: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
form.inline { display: inline; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .seg button:focus-visible, .page-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(16, 24, 40, .05); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.alert { padding: 10px 12px; border-radius: 8px; margin: 0 0 16px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }

.flash {
  margin: 16px auto 0;
  max-width: 960px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ok-soft);
  color: var(--ok);
  font-weight: 500;
}
.page-dashboard .flash { margin: 12px 16px 0; max-width: none; }

pre.code {
  margin: 8px 0;
  padding: 12px 14px;
  background: #101828;
  color: #e6e9ef;
  border-radius: 8px;
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- Kopfleiste ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }
.logout { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user { color: var(--muted); font-size: 13px; }

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

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 4px 0 8px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }

/* ---------- Inhaltsseiten ---------- */

.container { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty-state h1 { margin-bottom: 8px; }
.empty-state .btn { margin-top: 12px; }

.site { scroll-margin-top: calc(var(--topbar) + 16px); }
.site-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.site-head p { margin: 4px 0 0; }
.site-stats { display: flex; gap: 24px; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 16px 0; }
.meta dt { color: var(--muted); font-weight: 600; }
.meta dd { margin: 0; }

.embed { border-top: 1px solid var(--border); padding-top: 12px; margin: 12px 0; }
.embed summary { cursor: pointer; font-weight: 600; color: var(--accent-strong); }
.embed[open] summary { margin-bottom: 4px; }

.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }

/* ---------- Auswertung ---------- */

.page-dashboard { overflow: hidden; }

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: calc(100vh - var(--topbar));
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.filters { display: flex; flex-direction: column; gap: 16px; padding: 16px; border-bottom: 1px solid var(--border); }
.date-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.date-row input { padding: 6px 8px; font-size: 13px; }

.seg {
  display: flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.seg button {
  flex: 1;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow); }

.pages { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 16px 0 0; }
.pages-head { display: flex; justify-content: space-between; padding: 0 16px 8px; }
.pages input[type="search"] { margin: 0 16px 8px; width: calc(100% - 32px); }
.page-list { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; transition: opacity .2s; }
.page-list.is-loading { opacity: .45; }
.page-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.page-item:hover { background: var(--surface-2); }
.page-item.is-active { background: var(--accent-soft); border-left-color: var(--accent); }
.page-path { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.page-empty { padding: 12px 10px; color: var(--muted); }

.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.viewer-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 32px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.viewer-title { min-width: 0; flex: 1 1 240px; }
.viewer-title h1 { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-title a { font-size: 13px; text-decoration: none; }
.viewer-title a:hover { color: var(--accent-strong); }
.viewer-title a:not([href]) { display: none; }
.stats { display: flex; gap: 28px; }

.legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.legend-bar {
  width: 96px;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #2b4cff, #00c8ff 35%, #22e36b 55%, #ffe500 78%, #ff2200);
}

.viewer-sub {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 20px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.viewer-sub .muted { font-weight: 400; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  background:
    linear-gradient(45deg, #e9ebef 25%, transparent 25%, transparent 75%, #e9ebef 75%) 0 0 / 20px 20px,
    linear-gradient(45deg, #e9ebef 25%, transparent 25%, transparent 75%, #e9ebef 75%) 10px 10px / 20px 20px,
    #f1f2f5;
}
.frame-wrap {
  position: relative;
  overflow: hidden;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(16, 24, 40, .14), 0 0 0 1px rgba(16, 24, 40, .06);
}
.frame-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  border: 0;
  background: #fff;
  transform-origin: 0 0;
}

.stage-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100% - 48px));
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(16, 24, 40, .16);
  text-align: center;
  line-height: 1.55;
}
.stage-msg.is-warn { border-left: 4px solid var(--accent); text-align: left; }
.stage-msg.is-loading::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .page-dashboard { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .page-list { max-height: 260px; }
  .stage { height: 75vh; flex: none; }
  .topbar { gap: 12px; }
  .user { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
