:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1d2330;
  --muted: #646d7c;
  --accent: #2f5bd3;
  --accent-hover: #2449ad;
  --accent-soft: #e8eefc;
  --ok: #18794e;
  --ok-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --err: #b42318;
  --err-soft: #fde9e7;
  --info-soft: #e9f2fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #222733;
    --border: #2f3542;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --accent: #7b9cff;
    --accent-hover: #9bb4ff;
    --accent-soft: #232c45;
    --ok: #5cd39a;
    --ok-soft: #17301f;
    --warn: #f1b851;
    --warn-soft: #33290f;
    --err: #ff8a80;
    --err-soft: #3a1c1a;
    --info-soft: #1b2a3c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: .4rem 0 .8rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
small, .muted { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .7rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a {
  padding: .35rem .7rem; border-radius: 7px; color: var(--muted); font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar form { margin: 0; }

.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.title-line { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: .35rem; color: var(--muted); font-size: .9rem; }

/* Karten */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.card > h2:first-child { margin-top: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; }
.layout-edit { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.sticky { position: sticky; top: 4.5rem; }
@media (max-width: 960px) {
  .grid-2, .layout-edit { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
}

/* Kennzahlen */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.stat-label { display: block; color: var(--muted); font-size: .82rem; }
.stat-value { display: block; font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat a { color: inherit; }
.stat.ok .stat-value { color: var(--ok); }
.stat.err .stat-value { color: var(--err); }
.stat.warn .stat-value { color: var(--warn); }

/* Kampagnenliste */
.campaign-list { display: grid; gap: .75rem; }
.campaign-card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.2rem; color: var(--text); box-shadow: var(--shadow);
}
.campaign-card:hover { border-color: var(--accent); text-decoration: none; }
.cc-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .55rem; }
.cc-meta, .cc-next { color: var(--muted); font-size: .9rem; margin-top: .35rem; }
.cc-next strong { color: var(--text); font-weight: 600; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* Badges */
.badge {
  display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.status-active, .status-sent { background: var(--ok-soft); color: var(--ok); }
.status-paused, .status-skipped, .status-unknown { background: var(--warn-soft); color: var(--warn); }
.status-failed { background: var(--err-soft); color: var(--err); }
.status-draft, .status-pending { background: var(--surface-2); color: var(--muted); }
.status-completed, .status-sending { background: var(--accent-soft); color: var(--accent); }
.status-done { background: var(--ok-soft); color: var(--ok); }
.status-error { background: var(--err-soft); color: var(--err); }
.status-running { background: var(--accent-soft); color: var(--accent); }

/* Hinweise */
.flashes { display: grid; gap: .5rem; margin-bottom: 1rem; }
.callout {
  padding: .75rem 1rem; border-radius: 8px; border: 1px solid transparent; background: var(--info-soft);
}
.callout.success { background: var(--ok-soft); color: var(--ok); }
.callout.warning, .callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.error { background: var(--err-soft); color: var(--err); }
.callout ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.callout a { color: inherit; text-decoration: underline; }
.callout + .callout { margin-top: .5rem; }

/* Formulare */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem 1rem; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: .84rem; margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search],
select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
textarea.body-editor { min-height: 300px; }
textarea.mono { font-size: .85rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=file] { font: inherit; max-width: 100%; }
.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 500; margin-bottom: .6rem; }
.check input { margin-top: .25rem; }
.inline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.inline input[type=number] { width: 6.5rem; }
.inline input[type=email] { width: auto; min-width: 14rem; flex: 1; }

.days { display: flex; gap: .35rem; flex-wrap: wrap; }
.days label {
  margin: 0; font-weight: 600; cursor: pointer; user-select: none;
}
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days span {
  display: inline-block; min-width: 2.6rem; text-align: center; padding: .4rem .55rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.days input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.days input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin: .25rem 0 .6rem; }
.chip {
  border: 1px dashed var(--border); background: var(--surface-2); color: var(--text); border-radius: 6px;
  padding: .15rem .5rem; font: .82rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.builtin { border-style: solid; background: var(--accent-soft); color: var(--accent); }

.mapping { width: 100%; border-collapse: collapse; }
.mapping td { padding: .3rem 0; vertical-align: middle; }
.mapping td:first-child { width: 38%; font-weight: 600; font-size: .9rem; padding-right: .75rem; }
.mapping .sample { color: var(--muted); font-size: .82rem; display: block; margin-top: .15rem; min-height: 1em; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: var(--err-soft); }
.btn.small { padding: .25rem .6rem; font-size: .82rem; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 500; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.button-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.form-actions {
  display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; justify-content: space-between;
  position: sticky; bottom: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .8rem 1rem; box-shadow: 0 -2px 8px rgba(16, 24, 40, .06);
}
form.inline-form { display: inline; margin: 0; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .02em;
  border-bottom: 1px solid var(--border); padding: .5rem .6rem; white-space: nowrap;
}
table.data td { border-bottom: 1px solid var(--border); padding: .5rem .6rem; vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.nowrap { white-space: nowrap; }
table.data .err-text { color: var(--err); font-size: .84rem; }
table.data .skip-text { color: var(--warn); font-size: .84rem; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .75rem; }
.tabs a { padding: .3rem .65rem; border-radius: 7px; color: var(--muted); font-size: .88rem; font-weight: 500; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.pager { display: flex; gap: .5rem; align-items: center; justify-content: flex-end; margin-top: .75rem; font-size: .9rem; }
.level-error { color: var(--err); font-weight: 600; }
.level-warning { color: var(--warn); font-weight: 600; }

/* Vorschau */
.preview-head { font-size: .88rem; border-bottom: 1px solid var(--border); padding-bottom: .6rem; margin-bottom: .6rem; }
.preview-head div { display: flex; gap: .5rem; padding: .1rem 0; }
.preview-head dt, .preview-head .k { color: var(--muted); min-width: 4.2rem; }
.preview-head .v { font-weight: 500; word-break: break-word; }
.preview-subject { font-weight: 650 !important; }
.preview-frame { width: 100%; height: 460px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.preview-nav { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.preview-nav .pos { font-size: .88rem; color: var(--muted); text-align: center; flex: 1; }
.sig-frame { width: 100%; height: 160px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

.plan-list { list-style: none; margin: 0; padding: 0; }
.plan-list li { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px dashed var(--border); font-size: .92rem; }
.plan-list li:last-child { border-bottom: 0; }

.running-box { border-color: var(--accent); background: var(--accent-soft); }
.running-box .progress { background: var(--surface); margin: .5rem 0; }
.banner {
  display: block; background: var(--accent); color: #fff; text-align: center; padding: .4rem 1rem; font-size: .9rem;
}
.banner a { color: #fff; text-decoration: underline; }
.empty { text-align: center; padding: 2.5rem 1rem; }
.empty ol { display: inline-block; text-align: left; color: var(--muted); }
.steps { counter-reset: s; list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .75rem; }
.steps li { background: var(--surface-2); border-radius: 8px; padding: .8rem 1rem; text-align: left; }
.steps li::before { counter-increment: s; content: counter(s); display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; margin-right: .5rem; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: .5rem; }
.login { max-width: 380px; margin: 4rem auto; }
.account-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; }
.account-chip { background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; display: grid; gap: .3rem; }
.account-chip span { color: var(--muted); font-size: .88rem; }

@media (max-width: 600px), (max-height: 500px) {
  .topbar, .form-actions { position: static; }
  .sticky { position: static; }
}
@media (max-width: 600px) {
  .topbar { gap: .4rem .75rem; padding: .6rem 1rem; }
  .topbar nav { order: 3; flex: 1 1 100%; gap: .2rem; }
  .topbar nav a { padding: .3rem .55rem; }
  .container { padding: 1rem 1rem 3rem; }
  .preview-frame { height: 380px; }
}
