:root {
  --bg: #0b1020;
  --bg-soft: #101737;
  --surface: #ffffff;
  --surface-2: #f4f6fb;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info-bg: #e0e7ff;
  --info-ink: #3730a3;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 55px rgba(15, 23, 42, .12);
  --shadow-sm: 0 8px 24px rgba(15, 23, 42, .08);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 88% -6rem, #e0e7ff 0, transparent 30rem),
    radial-gradient(circle at -8rem 22rem, #ede9fe 0, transparent 26rem),
    var(--surface-2);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }
code, .mono { font-family: var(--mono); }

.shell { max-width: 1280px; margin: 0 auto; padding: 22px 22px 72px; }

/* ---------- App navigation ---------- */
.appnav {
  position: sticky;
  top: 12px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(226, 232, 240, .9);
  border-radius: 20px;
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 22px;
}
.appnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  padding: 6px 10px 6px 6px;
  border-radius: 14px;
  white-space: nowrap;
}
.appnav-brand:hover { background: #f1f5f9; }
.appnav-logo {
  width: 36px; height: 36px;
  border-radius: 12px;
  display: grid; place-items: center;
  color: #fff; font-weight: 900; font-size: 17px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 20px rgba(79, 70, 229, .35);
  flex: none;
}
.appnav-name { font-weight: 900; letter-spacing: -.03em; font-size: 17px; line-height: 1.05; }
.appnav-name small { display: block; font-weight: 600; font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.appnav-links { display: flex; align-items: center; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.appnav-links::-webkit-scrollbar { display: none; }
.appnav-links a {
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 14px;
  padding: 9px 13px;
  border-radius: 11px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.appnav-links a:hover { background: #eef2ff; color: var(--ink); }
.appnav-links a.active { background: var(--ink); color: #fff; }
.appnav-links a .dot { width: 7px; height: 7px; border-radius: 99px; background: currentColor; opacity: .55; }
.appnav-links a.active .dot { background: #a5b4fc; opacity: 1; }
.appnav-user { display: flex; align-items: center; gap: 8px; flex: none; }
.appnav-user form { margin: 0; }
.link-button {
  background: transparent; border: 0; color: var(--ink-soft);
  font: inherit; font-weight: 700; font-size: 14px;
  padding: 9px 12px; border-radius: 11px; cursor: pointer;
}
.link-button:hover { background: #f1f5f9; color: var(--ink); }
.nav-toggle {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 11px;
  padding: 9px 12px;
  font: inherit; font-weight: 800; font-size: 14px;
  cursor: pointer; color: var(--ink);
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, .8fr);
  gap: 24px;
  background:
    radial-gradient(circle at 92% 8%, rgba(129, 140, 248, .35) 0, transparent 22rem),
    radial-gradient(circle at 8% 110%, rgba(124, 58, 237, .35) 0, transparent 20rem),
    linear-gradient(135deg, #0f172a, #1e1b4b 70%, #312e81);
  color: #fff;
  border-radius: 26px;
  padding: 36px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.hero h1 {
  font-size: clamp(30px, 4vw, 52px);
  letter-spacing: -.05em; line-height: 1.02;
  margin: 10px 0 12px; max-width: 16ch;
}
.hero p { color: #cbd5e1; max-width: 66ch; line-height: 1.6; margin: 0 0 18px; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .14em;
  font-size: 11px; font-weight: 800; color: #a5b4fc;
}
.eyebrow.on-light { color: var(--brand); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-actions form { margin: 0; }
.hero-side {
  align-self: stretch;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 20px;
  padding: 22px;
  display: flex; flex-direction: column; justify-content: center; gap: 14px;
  backdrop-filter: blur(6px);
}
.hero-side .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hero-side .big { font-size: clamp(21px, 2.2vw, 30px); font-weight: 900; letter-spacing: -.04em; text-wrap: balance; overflow-wrap: anywhere; }
.hero-side .sub { color: #cbd5e1; font-size: 13px; line-height: 1.5; }

/* ---------- Buttons / forms ---------- */
.button, button.btn, input[type="submit"].btn {
  appearance: none; border: 0; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font: inherit; font-weight: 750;
  padding: 12px 16px; text-decoration: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 10px 24px rgba(79, 70, 229, .28);
}
.button:hover, button.btn:hover { filter: brightness(1.06); }
.button.secondary, button.secondary {
  background: #fff; color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.button.ghost, button.ghost {
  background: rgba(255, 255, 255, .12); color: #fff;
  border: 1px solid rgba(255, 255, 255, .22); box-shadow: none;
}
.button.danger, button.danger { background: var(--bad); box-shadow: 0 10px 24px rgba(185, 28, 28, .25); }
.button:disabled, button:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
label.field { display: block; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
label.field input, label.field select,
input.text, select.text {
  width: 100%; display: block; margin-top: 7px;
  padding: 12px 13px; border: 1px solid #cbd5e1; border-radius: 11px;
  background: #fff; font: inherit; font-weight: 500; color: var(--ink);
  text-transform: none; letter-spacing: 0;
}
input.text:focus, select.text:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  opacity: .9;
}
.kpi .label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.kpi strong { display: block; font-size: 30px; letter-spacing: -.04em; margin: 8px 0 6px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); line-height: 1.5; display: block; }
.kpi .delta-row { margin: 2px 0 8px; }

/* ---------- Panels / tables ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.panel h2 { margin: 2px 0 4px; font-size: 22px; letter-spacing: -.02em; }
.panel .lede { color: var(--muted); margin: 0 0 14px; line-height: 1.55; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head .tools { display: flex; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.empty { color: var(--muted); text-align: center; padding: 22px; }
td .wrap-cell, .wrap-cell { overflow-wrap: anywhere; }
.cell-main { font-weight: 750; display: block; }
.cell-sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Badges / deltas ---------- */
.badge, .status, .provider {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap;
}
.badge.ok, .status.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn, .status.warn { background: var(--warn-bg); color: var(--warn); }
.badge.off, .status.off { background: var(--bad-bg); color: var(--bad); }
.badge.info, .status.info { background: var(--info-bg); color: var(--info-ink); }
.badge.neutral, .status.neutral { background: #f1f5f9; color: #475569; }
.provider { background: #eef2ff; color: #3730a3; }
.provider.bing { background: #ecfdf5; color: #047857; }
.provider.google { background: #eef2ff; color: #3730a3; }
.delta { display: inline-flex; align-items: center; gap: 5px; font-weight: 800; font-size: 13px; padding: 4px 9px; border-radius: 999px; }
.delta.up { background: var(--ok-bg); color: var(--ok); }
.delta.down { background: var(--bad-bg); color: var(--bad); }
.delta.neutral { background: #f1f5f9; color: #475569; }
.bar { height: 8px; border-radius: 99px; background: #eef2ff; overflow: hidden; min-width: 70px; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }

/* ---------- Charts ---------- */
.chart-card canvas, canvas.chart { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.chart-tip {
  position: fixed; z-index: 80; pointer-events: none;
  background: #0f172a; color: #f8fafc;
  font-size: 12px; line-height: 1.5;
  padding: 9px 11px; border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .35);
  opacity: 0; transition: opacity .12s ease;
  max-width: 260px;
}
.chart-tip strong { display: block; font-size: 12px; }
.chart-empty { color: var(--muted); padding: 26px; text-align: center; font-size: 14px; }

/* ---------- Filters ---------- */
.filters {
  display: grid; grid-template-columns: 2fr 1fr 1fr auto;
  gap: 12px; background: #fff; align-items: end;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.filters.inline-5 { grid-template-columns: 1.6fr 1fr 1fr 1fr; }
.filters.inline-5 .actions { grid-column: 1 / -1; justify-content: flex-end; }
.filters.verlauf-filters { display: grid; gap: 12px; grid-template-columns: 1fr; }
.filters-row {
  display: grid; gap: 12px; align-items: end;
  grid-template-columns: 1.4fr 1.4fr 1fr 1.4fr;
}
.verlauf-filters .filters-row + .filters-row { grid-template-columns: 1fr 1fr 1.6fr auto; }
.filters .actions { align-self: end; display: flex; gap: 8px; }

/* ---------- Notices ---------- */
.notice, .flash, .sync-banner {
  border-radius: 14px; padding: 14px 16px; margin-bottom: 16px;
  border: 1px solid; line-height: 1.55; font-size: 14px;
}
.flash.success, .notice.ready, .sync-banner.done { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash.warning, .notice, .sync-banner.waiting { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash.error, .sync-banner.failed { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.sync-banner.running { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }
.note {
  background: #f8fafc; border: 1px dashed #cbd5e1; color: var(--ink-soft);
  border-radius: 14px; padding: 13px 15px; margin-bottom: 16px; font-size: 13px; line-height: 1.6;
}
.coverage-note { color: var(--muted); font-size: 13px; margin: -6px 0 16px; }
.progress-track { background: #eef2ff; border-radius: 99px; height: 12px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .6s ease; }
.history-meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ---------- Misc blocks ---------- */
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.provider-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.provider-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.provider-title small { color: var(--muted); }
.provider-values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.provider-values div { background: #f8fafc; border: 1px solid #eef2ff; border-radius: 12px; padding: 12px; }
.provider-values span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 800; letter-spacing: .06em; }
.provider-values strong { font-size: 20px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.coverage { font-size: 13px; border-radius: 10px; padding: 9px 11px; margin: 12px 0 0; }
.coverage.ok { background: #ecfdf5; color: #065f46; }
.coverage.warn { background: #fffbeb; color: #92400e; }
.endpoint, .codebox {
  display: block; background: #0f172a; color: #e2e8f0;
  border-radius: 12px; padding: 12px 14px;
  font: 13px var(--mono); word-break: break-all; margin: 10px 0; line-height: 1.6;
}
.endpoint.light { background: #f8fafc; color: var(--ink); border: 1px solid var(--line); }
.tokenbox { display: block; background: #0f172a; color: #f8fafc; border-radius: 12px; padding: 15px; font: 13px var(--mono); word-break: break-all; margin: 12px 0; }
.kv { display: grid; grid-template-columns: 190px 1fr; gap: 8px 14px; margin: 14px 0; font-size: 14px; align-items: start; }
.kv code { background: #f1f5f9; border: 1px solid var(--line); padding: 6px 9px; border-radius: 8px; word-break: break-all; font-size: 12px; }
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; }
.actions-row form { margin: 0; }
.actions-row .btn, .actions-row .ghost {
  flex: 1 1 0; min-width: 200px; white-space: normal; text-align: center; line-height: 1.35;
}
.hero-primary { align-items: stretch; }
.sync-secondary { margin: 12px 0 0; }
.link-button.on-dark { background: transparent; color: #e0e7ff; text-decoration: underline; text-underline-offset: 3px; font-size: 13.5px; font-weight: 700; padding: 6px 0; }
.link-button.on-dark:hover { background: transparent; color: #fff; }
.sync-status {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 12px; padding: 10px 14px; margin: 0; font-size: 13px; color: #e0e7ff;
}
.pulse { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; flex: none; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.8); } }
.tools-list { margin: 10px 0 0; padding-left: 0; list-style: none; display: grid; gap: 8px; }
.tools-list li { background: #f8fafc; border: 1px solid #eef2ff; border-radius: 10px; padding: 9px 12px; font-size: 13px; }
.tools-list code { font-weight: 800; color: var(--brand); }
.login-wrap { min-height: 86vh; display: grid; place-items: center; padding: 30px 16px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 24px; padding: 34px; width: min(430px, 100%); box-shadow: var(--shadow); }
.login-card h1 { margin: 10px 0 4px; letter-spacing: -.03em; }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }
.danger-zone { background: #fff; border: 1px dashed #fca5a5; border-radius: var(--radius); padding: 18px 22px; margin-bottom: 16px; }
.danger-zone summary { cursor: pointer; font-weight: 800; }
.footer { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 0 8px; }
.footer a { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* OAuth debug log */
.dbg-log { display: grid; gap: 10px; margin-top: 12px; }
.dbg-entry { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #f8fafc; font-size: 13px; }
.dbg-entry header { display: flex; gap: 8px; flex-wrap: wrap; font-weight: 800; margin-bottom: 6px; }
.dbg-ts { color: var(--muted); font-weight: 600; }
.dbg-ep { background: #e0e7ff; color: #3730a3; border-radius: 7px; padding: 2px 8px; }
.dbg-ev { color: var(--ink); }
.dbg-dl { margin: 6px 0 0; display: grid; grid-template-columns: 180px 1fr; gap: 4px 12px; }
.dbg-dl dt { color: var(--muted); font-weight: 700; overflow-wrap: anywhere; }
.dbg-dl dd { margin: 0; overflow-wrap: anywhere; }
.dbg-empty { color: #94a3b8; }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .hero { grid-template-columns: 1fr; padding: 28px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .provider-grid { grid-template-columns: 1fr; }
  .filters, .filters.inline-5 { grid-template-columns: 1fr 1fr; }
  .filters .actions { grid-column: 1 / -1; }
  .filters-row, .verlauf-filters .filters-row + .filters-row { grid-template-columns: 1fr 1fr; }
  .filters-row .actions { grid-column: 1 / -1; justify-content: flex-end; }
}
@media (max-width: 760px) {
  .shell { padding: 14px 12px 60px; }
  .appnav { top: 8px; flex-wrap: wrap; }
  .nav-toggle { display: inline-flex; margin-left: auto; }
  .appnav-links {
    display: none; flex-basis: 100%; flex-direction: column;
    align-items: stretch; max-height: 60vh;
  }
  .appnav.open .appnav-links { display: flex; }
  .appnav-links a { padding: 12px 14px; }
  .appnav-user { margin-left: auto; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .filters, .filters.inline-5 { grid-template-columns: 1fr; }
  .filters-row, .verlauf-filters .filters-row + .filters-row { grid-template-columns: 1fr; }
  .filters-row .actions { grid-column: auto; }
  .provider-values { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .dbg-dl { grid-template-columns: 1fr; }
  .panel { padding: 18px; }
}
@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr; }
}
