:root {
  --orange: #fe8627;
  --orange-strong: #ea7010;
  --orange-ink: #a84300;
  --orange-soft: #fff1e4;
  --ink: #17191c;
  --muted: #5d636b;
  --line: #e7e3dd;
  --bg: #faf9f7;
  --surface: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --ok: #1d7a45;
  --ok-soft: #e6f4ec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 25, 28, 0.06), 0 6px 18px rgba(23, 25, 28, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-wrap: anywhere;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
.muted { color: var(--muted); }

.boot { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }

/* Kopfzeile und Navigation */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; }
.brand img { height: 30px; width: auto; flex: none; }
.wordmark { font-weight: 500; letter-spacing: 0.2em; font-size: 13px; white-space: nowrap; }
.wordmark span { color: var(--orange); }
.nav { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.nav-link {
  padding: 10px 14px; text-decoration: none; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.nav-link:hover { color: var(--ink); }
.nav-link.active { color: var(--ink); border-bottom-color: var(--orange); }
.main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; min-width: 0; }
.main:focus { outline: none; }

/* Elemente */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 24px; line-height: 1.2; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
  padding: 0 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #cfc9c0; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #17191c; }
.btn.primary:hover { background: var(--orange-strong); border-color: var(--orange-strong); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 12px; }
.search { flex: 1 1 240px; min-width: 0; }
.input, select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; background: var(--surface);
  border: 1px solid #d4cec5; border-radius: 10px; font-size: 16px;
}
textarea { resize: vertical; line-height: 1.5; }
.input:focus, select:focus, textarea:focus { outline: 3px solid rgba(254, 134, 39, 0.35); border-color: var(--orange); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.count { margin-bottom: 8px; font-size: 14px; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: #eceae6; color: #3d4248; white-space: nowrap;
}
.badge.neu { background: #e8eef7; color: #26467a; }
.badge.kontaktiert { background: #fdf3cf; color: #6d5400; }
.badge.call_gebucht { background: var(--orange-soft); color: var(--orange-ink); }
.badge.call_gehalten { background: #ffe0c7; color: #8a3b00; }
.badge.gewonnen, .badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.verloren, .badge.inactive { background: #eceae6; color: #5d636b; }

/* Listen */
.list { display: grid; gap: 8px; }
.row {
  display: grid; gap: 6px 16px; width: 100%; padding: 14px 16px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0;
}
.row:hover { border-color: var(--orange); }
.row > * { min-width: 0; }
.row .name { font-weight: 700; }
.row .sub { color: var(--muted); font-size: 14px; }
.page { display: grid; gap: 16px; }
.page > .page-head { margin-bottom: 0; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
@media (min-width: 820px) {
  .row.lead { grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 1.4fr) minmax(0, 0.9fr); align-items: center; }
  .row.customer { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 1.6fr) minmax(0, 1fr); align-items: center; }
}
.row .stack { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }

/* Dialog */
dialog#modal {
  padding: 0; border: 0; border-radius: 16px; width: min(780px, calc(100% - 32px));
  max-height: calc(100dvh - 32px); background: var(--bg); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog#modal::backdrop { background: rgba(23, 25, 28, 0.5); }
dialog#modal[open] { display: flex; flex-direction: column; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 20px; line-height: 1.25; min-width: 0; }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; display: grid; gap: 20px; align-content: start; }
.modal-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 20px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.modal-foot .form-error { flex: 1 1 100%; margin: 0; }
@media (max-width: 640px) {
  dialog#modal { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .modal-foot .btn { flex: 1; }
}

/* Formulare */
#contact-form { display: grid; gap: 20px; }
.section { display: grid; gap: 12px; }
.section > h3 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.label { font-size: 14px; font-weight: 700; }
.hint { font-size: 13px; color: var(--muted); }
.notes-area { min-height: 260px; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 10px 12px; font-size: 15px; margin-top: 4px; }
.form-error:empty { display: none; }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(440px, 100%); display: grid; gap: 16px; }
.auth-logo { display: block; width: 180px; max-width: 70%; height: auto; margin: 0 auto; }
.auth-card h1 { font-size: 22px; text-align: center; }
.auth-card p.muted { text-align: center; }

/* Transkripte und Verlauf */
.transcripts { display: grid; gap: 10px; }
.transcripts-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
details.item { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
details.item > summary { cursor: pointer; padding: 12px 14px; font-weight: 700; list-style-position: inside; }
details.item .item-body { padding: 0 14px 14px; display: grid; gap: 10px; }
.transcript-text { white-space: pre-wrap; font: inherit; margin: 0; max-height: 320px; overflow: auto; padding: 12px; background: var(--bg); border-radius: 8px; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.history { list-style: none; margin: 0; padding: 0 14px 12px; display: grid; gap: 10px; }
.history li { font-size: 14px; }
.history .when { color: var(--muted); display: block; }

/* Statistiken */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 4px; }
.tile { padding: 14px 16px; }
.tile .tile-label { color: var(--muted); font-size: 14px; font-weight: 600; }
.tile .tile-value { font-size: clamp(20px, 5vw, 26px); font-weight: 800; line-height: 1.2; margin-top: 4px; }
.bars { display: grid; gap: 4px; }
.bar-row {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) 150px; grid-template-areas: "label track value";
  gap: 4px 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line);
}
.bar-row:last-child { border-bottom: 0; }
.bar-label { grid-area: label; font-weight: 700; }
.bar-track { grid-area: track; height: 14px; background: #f1ede7; border-radius: 7px; overflow: hidden; }
.bar-fill { width: var(--w, 0%); height: 100%; background: var(--orange); border-radius: 7px; }
.bar-value { grid-area: value; display: grid; text-align: right; line-height: 1.3; }
.bar-value span { font-size: 13px; }
@media (max-width: 520px) {
  .bar-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label value" "track track"; }
}

/* Team */
.user-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }

/* Hinweise */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 200; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

/* Handy: Menü unten, damit nichts seitlich scrollt */
@media (max-width: 720px) {
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; padding: 0 0 env(safe-area-inset-bottom);
    border-top: 1px solid var(--line); border-bottom: 0; overflow: visible; gap: 0;
  }
  .nav-link { flex: 1 1 0; min-width: 0; text-align: center; padding: 14px 2px 12px; font-size: 13px; border-bottom: 0; border-top: 3px solid transparent; overflow: hidden; text-overflow: ellipsis; }
  .nav-link.active { border-top-color: var(--orange); }
  .main { padding-bottom: 96px; }
  .toasts { bottom: 84px; }
}
@media (max-width: 360px) {
  .nav-link { font-size: 12px; padding-left: 0; padding-right: 0; }
  .wordmark { font-size: 12px; letter-spacing: 0.14em; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .page-head h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
