:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e2e7ee;
  --line-2: #cfd7e2;
  --text: #16202e;
  --muted: #637083;
  --accent: #1f5fbf;
  --accent-hover: #184f9f;
  --accent-soft: #e7effb;
  --accent-2: #12a37f;
  --ok: #12805f;
  --ok-soft: #e3f4ee;
  --warn: #a8600a;
  --warn-soft: #fbf0df;
  --bad: #b3322d;
  --bad-soft: #fbe6e5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --panel: #161d27;
    --panel-2: #1b2430;
    --line: #263142;
    --line-2: #33415a;
    --text: #e6ebf2;
    --muted: #93a0b3;
    --accent: #5b9bf0;
    --accent-hover: #79aef5;
    --accent-soft: #1d2e47;
    --accent-2: #3cc79f;
    --ok: #4cc59a;
    --ok-soft: #173329;
    --warn: #e2a24a;
    --warn-soft: #3a2b16;
    --bad: #ef7a74;
    --bad-soft: #3d1d1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body.ohne-close .nur-close { display: none !important; }
body:not(.team) .nur-team { display: none !important; }
body.rolle-vertrieb .nur-admin { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
h2 { font-size: 20px; margin: 0 0 2px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 0 0 12px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 12.5px; }

/* --- Kopfzeile --- */
.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 0 24px; height: 56px; flex: none;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; color: var(--accent); }
.brand span:first-of-type { color: var(--text); }
.tabs { display: flex; gap: 4px; height: 100%; }
.benutzer { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.benutzer #benutzer-name { font-weight: 600; color: var(--text); }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  font: inherit; font-weight: 550; padding: 0 12px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.count { background: var(--accent); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; line-height: 17px; }

main { flex: 1; min-height: 0; overflow: auto; }
.tab { display: none; padding: 24px; max-width: 1480px; margin: 0 auto; }
.tab.active { display: block; }
#tab-assistent.active { display: flex; justify-content: center; height: 100%; padding-bottom: 16px; }

.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* --- Bedienelemente --- */
button, .button {
  font: inherit; font-weight: 550; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.ghost, .button.ghost { background: transparent; }
button.small { padding: 5px 10px; font-size: 13px; }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); }
button.icon { border: 0; background: none; font-size: 24px; line-height: 1; padding: 2px 8px; color: var(--muted); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); width: 100%;
  border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; margin-bottom: 12px; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; font-size: 14px; }
.form label.narrow { max-width: 220px; }
.form.wide { max-width: 980px; }
.form h3:not(:first-child) { margin-top: 18px; }
.form-actions { display: flex; justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; align-items: start; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 14px 0 4px; }
legend { font-weight: 650; padding-right: 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.checks { display: flex; gap: 6px 18px; flex-wrap: wrap; margin-bottom: 12px; }
.checks label { flex-direction: row; align-items: center; gap: 6px; font-weight: normal; margin: 0; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.seg label { flex-direction: row; margin: 0; padding: 7px 14px; cursor: pointer; font-weight: 550; gap: 6px; }
.seg label:has(input:checked) { background: var(--accent-soft); color: var(--accent); }
.seg input { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; font-weight: normal; }
.chips .grp { width: 100%; font-size: 11.5px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
.chip { border: 1px solid var(--line-2); border-radius: 14px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; user-select: none; background: var(--panel); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.hint { font-weight: normal; color: var(--ok); font-size: 12px; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 650; border-radius: 6px; padding: 1px 7px; line-height: 18px; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.neutral { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }

/* --- Chat --- */
.chat-wrap { width: 100%; max-width: 920px; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 4px 2px 12px; min-height: 120px; }
.msg { max-width: 82%; padding: 11px 15px; border-radius: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.msg.assistant p + p, .msg.assistant p + ul, .msg.assistant ul + p, .msg.assistant p + ol, .msg.assistant ol + p { margin-top: 8px; }
.msg.assistant ul, .msg.assistant ol { margin: 6px 0 0; padding-left: 20px; }
.msg.assistant li + li { margin-top: 3px; }
.msg.denkt { color: var(--muted); font-style: italic; }
.msg.fehler { border-color: var(--bad); color: var(--bad); }
.dots::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.vorschlaege { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 10px; }
.vorschlaege button { font-weight: normal; font-size: 13px; border-radius: 16px; padding: 5px 12px; background: var(--panel); }
.chat-form { display: flex; gap: 10px; align-items: flex-end; }
.chat-form textarea { min-height: 52px; max-height: 200px; }
.chat-form button { height: 52px; }

.auftrag-karte { margin-top: 10px; border: 1px solid var(--line-2); border-radius: 10px; padding: 12px 14px; background: var(--panel-2); }
.auftrag-karte .titel { font-weight: 650; margin-bottom: 4px; }
.auftrag-karte .kv { font-size: 13px; color: var(--muted); }
.auftrag-karte .kv b { color: var(--text); font-weight: 550; }
.auftrag-karte .actions { margin-top: 10px; }

/* --- Aufträge --- */
.auftraege { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }
.auftrag { display: flex; flex-direction: column; gap: 10px; }
.auftrag .kopf { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.auftrag .name { font-weight: 650; font-size: 15px; }
.auftrag .kriterien { font-size: 13px; color: var(--muted); }
.progress { height: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s; }
.zahlen { display: flex; gap: 18px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.zahlen b { color: var(--text); font-size: 15px; }
.meldung { font-size: 13px; padding: 7px 10px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--line); }
.meldung.fehler { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.gruende { font-size: 12.5px; color: var(--muted); }
.leer { padding: 48px 20px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line-2); border-radius: var(--radius); }

/* --- Leads --- */
.filterbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.filterbar select { width: auto; min-width: 180px; }
.filterbar input { flex: 1; min-width: 220px; }
.bulkbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; padding: 8px 12px; border-radius: 9px; background: var(--accent-soft); flex-wrap: wrap; }
.bulkbar select { width: auto; }
.bulkbar span { font-weight: 650; color: var(--accent); }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table.leads { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.leads th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); white-space: nowrap; }
table.leads td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.leads tbody tr { cursor: pointer; }
table.leads tbody tr:hover { background: var(--panel-2); }
table.leads tr.sel { background: var(--accent-soft) !important; }
table.leads .cb { width: 34px; }
table.leads .firma { font-weight: 600; }
table.leads .sub { color: var(--muted); font-size: 12.5px; }
table.leads td.nowrap { white-space: nowrap; }
.passung { font-weight: 700; }
.passung.hoch { color: var(--ok); }
.passung.mittel { color: var(--warn); }
.passung.niedrig { color: var(--bad); }

/* --- Vertriebler --- */
.vertriebler { display: flex; flex-direction: column; gap: 12px; }
.vertriebler .card { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.vertriebler .name { font-weight: 650; font-size: 15px; }

/* --- Schubladen --- */
.drawer { position: fixed; inset: 0; background: rgba(15, 20, 27, .38); z-index: 20; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-panel { width: min(760px, 100%); height: 100%; background: var(--panel); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.drawer-panel > .form, .drawer-panel > .detail { flex: 1; overflow-y: auto; padding: 8px 22px 20px; }
.drawer-foot { border-top: 1px solid var(--line); padding: 12px 22px; display: flex; justify-content: space-between; align-items: center; gap: 14px; background: var(--panel-2); }
.vorschau { font-size: 13px; color: var(--muted); }
.vorschau b { color: var(--text); }
[data-nur][hidden] { display: none !important; }

.detail section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.detail section:last-child { border-bottom: 0; }
.detail h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.detail dl { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; margin: 0; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail ul { margin: 0; padding-left: 18px; }
.detail li + li { margin-top: 4px; }
.signale { display: flex; flex-wrap: wrap; gap: 6px; }

.modal { position: fixed; inset: 0; background: rgba(15, 20, 27, .45); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 20px 22px; width: min(480px, 100%); }
.modal-box .checks { flex-direction: column; gap: 8px; }
.modal-box label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; margin-bottom: 12px; }
.modal-box .checks label { flex-direction: row; font-weight: normal; font-size: 14px; margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.ergebnisliste { max-height: 280px; overflow: auto; font-size: 13px; margin: 0; padding-left: 18px; }

.nutzung { align-self: center; font-size: 13px; color: var(--muted); padding-top: 8px; }
.nutzung b { color: var(--text); }
#google-badge { margin-left: 8px; vertical-align: 1px; }

.fehlertext { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 7px; font-size: 13px; margin: 8px 0 12px; }
.modal-box p.small { margin: -6px 0 12px; }

.werbedaten { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 4px 0 10px; font-size: 13px; }
.werbedaten .info { flex-basis: 100%; color: var(--muted); }
.werbedaten .info b { color: var(--text); }
.anleitung { margin: 0 0 8px; font-size: 13.5px; }
.anleitung summary { cursor: pointer; color: var(--accent); font-weight: 550; margin-bottom: 6px; }
.anleitung ol { margin: 6px 0 10px; padding-left: 20px; }
.anleitung li + li { margin-top: 4px; }
textarea.code { font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.werbe-badges { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: 1px; }
.werbe-badges .badge { font-size: 10.5px; line-height: 16px; padding: 0 5px; }

.pruef { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 8px; font-size: 13px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 10px 18px; border-radius: 9px; box-shadow: var(--shadow); z-index: 40; max-width: 80vw; }
.toast.fehler { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .topbar { padding: 0 12px; gap: 12px; overflow-x: auto; }
  .brand span:first-of-type { display: none; }
  .tab { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .auftraege { grid-template-columns: 1fr; }
  .msg { max-width: 94%; }
  .detail dl { grid-template-columns: 1fr; }
}
