/* Elvyon CRM - Design-System (HubSpot-inspiriert: dicht, schlicht, hell) */

:root {
  --c-bg: #f5f8fa;
  --c-surface: #ffffff;
  --c-border: #dfe3eb;
  --c-border-strong: #cbd6e2;
  --c-text: #33475b;
  --c-text-soft: #516f90;
  --c-text-faint: #7c98b6;
  --c-accent: #ff7a59;
  --c-accent-hover: #ff8f73;
  --c-accent-press: #e66f50;
  --c-link: #0091ae;
  --c-sidebar: #2e3e4e;
  --c-sidebar-hover: #3b4d60;
  --c-sidebar-active: #ff7a59;
  --c-sidebar-text: #cbd6e2;

  --ok: #00bda5;
  --ok-bg: #e0f6f2;
  --warn: #e8a33d;
  --warn-bg: #fdf3e3;
  --danger: #f2545b;
  --danger-bg: #fde6e7;
  --info: #0091ae;
  --info-bg: #e1f1f4;
  --neutral: #7c98b6;
  --neutral-bg: #eaf0f6;
  --purple: #6a78d1;
  --purple-bg: #ebedfa;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-pop: 0 6px 24px rgba(45,62,80,.18);
  --sidebar-w: 208px;
  --ki-w: 384px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--c-link); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0; font-weight: 600; color: var(--c-text); }
button { font-family: inherit; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--c-sidebar);
  color: var(--c-sidebar-text);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0;
  z-index: 40;
}
.sidebar .brand {
  padding: 16px 18px;
  font-size: 17px; font-weight: 700; color: #fff;
  letter-spacing: .3px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand span { color: var(--c-accent); }
.sidebar nav { padding: 8px 0; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; color: var(--c-sidebar-text);
  font-size: 13px; cursor: pointer; border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--c-sidebar-hover); text-decoration: none; }
.nav-item.active { background: var(--c-sidebar-hover); color: #fff; border-left-color: var(--c-accent); font-weight: 600; }
.nav-item .ico { width: 16px; height: 16px; flex: none; opacity: .85; }
.nav-section { padding: 12px 18px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--c-text-faint); }
.sidebar-actions { border-top: 1px solid rgba(255,255,255,.08); padding: 6px 0; }
.sidebar .foot { padding: 10px 14px; font-size: 11px; color: var(--c-text-faint); border-top: 1px solid rgba(255,255,255,.08); display:flex; flex-direction:column; align-items:stretch; gap:8px;}
.foot-user { display:flex; align-items:center; gap:8px; }
.foot-user .avatar { width:26px; height:26px; font-size:10px; background:rgba(255,255,255,.12); color:#fff; }
.foot-user .user-name { font-size:12px; font-weight:600; color:#fff; flex:1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.logout-btn { background:transparent; border:1px solid rgba(255,255,255,.25); color:var(--c-sidebar-text); font-size:11px; padding:3px 8px; border-radius:4px; cursor:pointer; }
.logout-btn:hover { background:rgba(255,255,255,.12); color:#fff; }
.sse-line { display:flex; align-items:center; gap:6px; }

/* ---------- Sidebar: Schnellnotiz ---------- */
.sidebar-notiz { border-top:1px solid rgba(255,255,255,.08); padding:10px 14px; display:flex; flex-direction:column; gap:6px; }
.sidebar-notiz .sn-title { font-size:10px; text-transform:uppercase; letter-spacing:.8px; color:var(--c-text-faint); display:flex; justify-content:space-between; align-items:center; }
.sidebar-notiz .sn-title a { color:var(--c-text-faint); }
.sidebar-notiz .sn-title a:hover { color:#fff; }
.sidebar-notiz textarea, .sidebar-notiz select {
  width:100%; border:1px solid rgba(255,255,255,.18); background:rgba(255,255,255,.06); color:#fff;
  border-radius:5px; font-size:12px; font-family:inherit;
}
.sidebar-notiz textarea { resize:vertical; min-height:46px; max-height:140px; padding:6px 8px; }
.sidebar-notiz select { height:28px; padding:0 6px; }
.sidebar-notiz textarea::placeholder { color:var(--c-text-faint); }
.sidebar-notiz textarea:focus, .sidebar-notiz select:focus { outline:none; border-color:var(--c-accent); background:rgba(255,255,255,.1); }
.sidebar-notiz select option { color:#33475b; }
.sidebar-notiz .sn-add { height:28px; }

/* ---------- Notizen-Ansicht ---------- */
.notiz-item { padding:12px 16px; border-bottom:1px solid var(--c-border); display:flex; gap:12px; align-items:flex-start; }
.notiz-item:last-child { border-bottom:none; }
.notiz-item .ni-main { flex:1; min-width:0; }
.notiz-item .ni-text { white-space:pre-wrap; font-size:13px; }
.notiz-item .ni-meta { font-size:11px; color:var(--c-text-faint); margin-top:5px; display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.notiz-item .ni-actions { display:flex; gap:4px; flex:none; }

/* ---------- Aufgaben-Kanban ---------- */
.kanban { display:flex; gap:14px; align-items:flex-start; overflow-x:auto; padding-bottom:10px; }
.kb-col { flex:0 0 280px; width:280px; background:var(--c-bg); border:1px solid var(--c-border); border-radius:8px; display:flex; flex-direction:column; max-height:calc(100vh - 170px); }
.kb-col.drop-target { outline:2px dashed var(--c-accent); outline-offset:-2px; background:#fff5f2; }
.kb-col-head { padding:9px 12px; display:flex; align-items:center; justify-content:space-between; gap:8px; border-bottom:1px solid var(--c-border); }
.kb-col-head .kb-title { font-weight:600; font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; cursor:pointer; }
.kb-col-head .kb-title:hover { color:var(--c-link); }
.kb-col-head .kb-count { font-size:11px; font-weight:700; color:var(--c-text-soft); background:var(--neutral-bg); border-radius:10px; padding:1px 8px; flex:none; }
.kb-col-head .kb-add { border:none; background:transparent; color:var(--c-text-soft); font-size:18px; line-height:1; cursor:pointer; padding:0 4px; }
.kb-col-head .kb-add:hover { color:var(--c-accent); }
.kb-cards { padding:10px; display:flex; flex-direction:column; gap:8px; overflow-y:auto; flex:1; min-height:48px; }
.kb-card { background:#fff; border:1px solid var(--c-border); border-left:3px solid var(--c-border-strong); border-radius:6px; box-shadow:var(--shadow); padding:9px 10px; cursor:pointer; }
.kb-card:hover { border-color:var(--c-border-strong); }
.kb-card.prio-hoch { border-left-color:var(--danger); }
.kb-card.prio-mittel { border-left-color:var(--info); }
.kb-card.prio-niedrig { border-left-color:var(--neutral); }
.kb-card.done { opacity:.55; }
.kb-card.done .kb-card-title { text-decoration:line-through; }
.kb-card.kb-dragging { opacity:.4; }
.kb-card-top { display:flex; align-items:flex-start; gap:8px; }
.kb-card-top input[type=checkbox] { margin-top:2px; flex:none; cursor:pointer; }
.kb-card-title { font-weight:600; font-size:13px; flex:1; min-width:0; word-break:break-word; }
.kb-card-body { font-size:12px; color:var(--c-text-soft); margin-top:5px; white-space:pre-wrap;
  display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden; }
.kb-card-foot { display:flex; align-items:center; gap:8px; margin-top:8px; flex-wrap:wrap; }
.kb-card-foot .kb-deadline { font-size:11px; color:var(--c-text-faint); }
.kb-card-foot .kb-deadline.overdue { color:var(--danger); font-weight:600; }
.kb-avatar { width:22px; height:22px; border-radius:50%; display:inline-flex; align-items:center; justify-content:center; font-size:9px; font-weight:700; color:#fff; flex:none; }
.kb-avatar.none { background:var(--neutral-bg); color:var(--c-text-faint); border:1px dashed var(--c-border-strong); }

/* ---------- Benachrichtigungen (Glocke) ---------- */
.bell-wrap { position:relative; }
.bell-btn { position:relative; width:34px; height:34px; border:1px solid var(--c-border-strong); background:#fff; border-radius:var(--radius); cursor:pointer; display:inline-flex; align-items:center; justify-content:center; color:var(--c-text-soft); }
.bell-btn:hover { background:var(--c-bg); color:var(--c-text); }
.bell-btn .ico { width:18px; height:18px; }
.bell-badge { position:absolute; top:-6px; right:-6px; background:var(--c-accent); color:#fff; font-size:10px; font-weight:700; min-width:16px; height:16px; line-height:16px; border-radius:8px; padding:0 4px; text-align:center; }
.bell-panel { position:absolute; top:44px; right:0; width:340px; max-height:440px; overflow-y:auto; background:#fff; border:1px solid var(--c-border); border-radius:var(--radius); box-shadow:var(--shadow-pop); z-index:60; }
.bell-head { padding:10px 12px; border-bottom:1px solid var(--c-border); display:flex; justify-content:space-between; align-items:center; position:sticky; top:0; background:#fff; }
.bell-head h4 { font-size:13px; }
.bell-item { padding:10px 12px; border-bottom:1px solid var(--c-border); cursor:pointer; display:flex; gap:8px; }
.bell-item:last-child { border-bottom:none; }
.bell-item:hover { background:var(--c-bg); }
.bell-item.unread { background:#fff7f4; }
.bell-item.unread:hover { background:#ffeee8; }
.bell-dot { width:8px; height:8px; border-radius:50%; background:var(--c-accent); margin-top:4px; flex:none; }
.bell-item .bi-text { font-size:12px; color:var(--c-text); }
.bell-item .bi-time { font-size:11px; color:var(--c-text-faint); margin-top:3px; }
.bell-empty { padding:26px 16px; text-align:center; color:var(--c-text-faint); font-size:12px; }

/* ---------- @-Erwähnung (Aufgaben-Beschreibung) ---------- */
.mention-box { position:relative; }
.mention-box textarea { width:100%; }
.mention-list { position:absolute; left:0; right:0; top:100%; background:#fff; border:1px solid var(--c-border); border-radius:var(--radius); box-shadow:var(--shadow-pop); z-index:140; max-height:180px; overflow-y:auto; }
.mention-opt { padding:6px 10px; cursor:pointer; display:flex; justify-content:space-between; gap:10px; font-size:12px; }
.mention-opt:hover, .mention-opt.active { background:var(--c-bg); }
.mention-opt .mo-user { color:var(--c-text-faint); }

/* ---------- Anhänge (Aufgabe) ---------- */
.anh-section .anh-list { display:flex; flex-direction:column; gap:5px; margin:4px 0 8px; }
.anh-item { display:flex; align-items:center; gap:8px; font-size:12px; }
.anh-item a { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.anh-item .anh-size { color:var(--c-text-faint); flex:none; }

/* ---------- Login ---------- */
.login-screen { position:fixed; inset:0; background:var(--c-bg); display:flex; align-items:center; justify-content:center; z-index:500; padding:20px; }
.login-card { background:#fff; border:1px solid var(--c-border); border-radius:8px; box-shadow:var(--shadow-pop); width:100%; max-width:340px; padding:28px 26px; }
.login-card .brand { font-size:21px; font-weight:700; color:var(--c-text); }
.login-card .brand span { color:var(--c-accent); margin:0 2px; }
.login-card .sub { font-size:12px; color:var(--c-text-soft); margin:2px 0 18px; }
.login-card .err { color:var(--danger); font-size:12px; min-height:16px; margin-bottom:8px; }
.login-card .field { margin-bottom:12px; }
.login-card .field input { width:100%; }
.login-card .btn { width:100%; justify-content:center; margin-top:4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); flex:none; }
.dot.on { background: var(--ok); }

.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--c-surface); border-bottom: 1px solid var(--c-border);
  height: 52px; display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
}
.topbar .search { position: relative; flex: 1; max-width: 460px; }
.topbar .search input {
  width: 100%; height: 34px; border: 1px solid var(--c-border-strong);
  border-radius: var(--radius); padding: 0 12px; font-size: 13px; background: var(--c-bg);
}
.topbar .search input:focus { outline: none; border-color: var(--c-accent); background:#fff; }
.search-results {
  position: absolute; top: 38px; left: 0; right: 0; background: #fff;
  border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  max-height: 360px; overflow-y: auto; z-index: 50;
}
.search-results .grp { padding: 6px 12px 2px; font-size: 10px; text-transform: uppercase; color: var(--c-text-faint); letter-spacing:.6px;}
.search-results .res { padding: 7px 12px; cursor: pointer; display:flex; justify-content:space-between; gap:8px;}
.search-results .res:hover { background: var(--c-bg); }
.search-results .res small { color: var(--c-text-faint); }

.content { padding: 20px 24px; flex: 1; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 16px; }
.page-head h1 { font-size: 20px; }
.page-head .sub { color: var(--c-text-soft); font-size: 12px; margin-top: 2px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--c-border-strong); background: #fff; color: var(--c-text);
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--c-bg); }
.btn.primary { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
.btn.primary:hover { background: var(--c-accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--c-link); }
.btn.ghost:hover { background: var(--c-bg); }
.btn.danger { color: var(--danger); border-color: var(--c-border-strong); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 28px; height: 28px; padding: 0; justify-content: center; }

/* ---------- Cards ---------- */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 12px 16px; border-bottom: 1px solid var(--c-border); display:flex; align-items:center; justify-content:space-between; gap:8px; }
.card-head h3 { font-size: 14px; }
.card-body { padding: 14px 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px){ .grid.cols-4{grid-template-columns:repeat(2,1fr);} .grid.cols-3{grid-template-columns:repeat(2,1fr);} }
@media (max-width: 760px){ .grid.cols-2,.grid.cols-3,.grid.cols-4{grid-template-columns:1fr;} }

/* ---------- Stat tiles ---------- */
.stat { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--c-text-faint); }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .meta { font-size: 11px; color: var(--c-text-soft); margin-top: 2px; }
.stat.accent .value { color: var(--c-accent); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--c-text-faint); font-weight: 600; padding: 8px 12px;
  border-bottom: 1px solid var(--c-border); white-space: nowrap; background: #fbfcfd;
}
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--c-bg); }
table.data tr.no-hover { cursor: default; }
table.data tr.no-hover:hover { background: transparent; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .nowrap { white-space: nowrap; }
.cell-strong { font-weight: 600; color: var(--c-text); }
.cell-soft { color: var(--c-text-soft); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600;
  background: var(--neutral-bg); color: var(--c-text-soft); white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }
.badge.accent { background: #ffe9e2; color: var(--c-accent-press); }
.badge .bdot { width:6px;height:6px;border-radius:50%;background:currentColor;}

/* type pills for interaktion */
.pill-typ { font-size:10px;font-weight:700;letter-spacing:.5px;text-transform:uppercase;padding:2px 6px;border-radius:4px;}
.pill-typ.call{background:var(--info-bg);color:var(--info);}
.pill-typ.whatsapp{background:var(--ok-bg);color:var(--ok);}
.pill-typ.email{background:var(--purple-bg);color:var(--purple);}
.pill-typ.note{background:var(--warn-bg);color:var(--warn);}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--c-border); margin-bottom: 16px; }
.tab { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--c-text-soft); cursor: pointer; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--c-text); }
.tab.active { color: var(--c-accent); border-bottom-color: var(--c-accent); }
.tab .count { font-size: 11px; color: var(--c-text-faint); margin-left: 4px; }

/* ---------- Detail layout ---------- */
.detail-grid { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px){ .detail-grid{grid-template-columns:1fr;} }
.prop { display: flex; flex-direction: column; gap: 1px; padding: 7px 0; border-bottom: 1px solid var(--c-border); }
.prop:last-child { border-bottom: none; }
.prop .k { font-size: 11px; color: var(--c-text-faint); text-transform: uppercase; letter-spacing: .4px; }
.prop .v { font-size: 13px; }
.breadcrumb { font-size: 12px; color: var(--c-text-soft); margin-bottom: 6px; }
.breadcrumb a { color: var(--c-text-soft); }

/* ---------- Timeline ---------- */
.timeline { position: relative; }
.tl-item { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--c-border); }
.tl-item:last-child { border-bottom: none; }
.tl-when { font-size: 11px; color: var(--c-text-faint); text-align: right; padding-top: 2px; }
.tl-body .tl-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; flex-wrap: wrap; }
.tl-body .tl-sub { font-size: 12px; color: var(--c-text-soft); }
.tl-body .tl-text { font-size: 13px; margin-top: 3px; white-space: pre-wrap; }
.tl-body .tl-meta { font-size:11px; color: var(--c-text-faint); margin-top: 4px; display:flex; gap:10px; flex-wrap:wrap;}

/* ---------- Forms / Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(45,62,80,.45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px 16px; overflow-y:auto;}
.modal { background: #fff; border-radius: 8px; box-shadow: var(--shadow-pop); width: 100%; max-width: 560px; max-height: calc(100vh - 48px); display: flex; flex-direction: column; }
.modal.wide { max-width: 840px; }
.modal-head { flex: none; padding: 14px 18px; border-bottom: 1px solid var(--c-border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 15px; }
.modal-body { flex: 1 1 auto; min-height: 0; padding: 18px; overflow-y: auto; }
.modal-foot { flex: none; padding: 12px 18px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 8px; }
.x-close { cursor: pointer; color: var(--c-text-faint); font-size: 20px; line-height: 1; border: none; background: none; }
.x-close:hover { color: var(--c-text); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; min-width: 0; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--c-text-soft); white-space: nowrap; }
.field input, .field select, .field textarea {
  border: 1px solid var(--c-border-strong); border-radius: var(--radius);
  padding: 7px 10px; font-size: 13px; font-family: inherit; color: var(--c-text); background:#fff;
  width: 100%; min-width: 0; box-sizing: border-box;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 3px rgba(255,122,89,.12); }
.field textarea { resize: vertical; min-height: 64px; }
/* Selects: native Optik vereinheitlichen (eigener Chevron, gleiche Höhe wie Inputs) */
.field select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 30px; cursor: pointer; line-height: 1.35;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23516f90' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 11px;
}
.field select:hover { border-color: var(--c-accent); background-color: #fafbfc; }
.field select:focus { background-color: #fff; }
.field select option { color: var(--c-text); }
.field select optgroup { font-weight: 700; color: var(--c-text-soft); }

/* ---------- Firma: zweispaltiges Anlege-Formular mit KI-Recherche ---------- */
.firma-suche { display: flex; gap: 8px; margin-bottom: 8px; }
.firma-suche-input { flex: 1; border: 1px solid var(--c-border-strong); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; font-family: inherit; color: var(--c-text); }
.firma-suche-input:focus { outline: none; border-color: var(--c-accent); }
.firma-suche-status { font-size: 12px; margin-bottom: 14px; }
.firma-suche-status.err { color: var(--danger); }
.firma-split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; min-width: 0; }
.firma-split.locked { opacity: .45; pointer-events: none; filter: grayscale(.4); }
/* solo = nur Firmen-Stammdaten (Kontaktperson-Schalter aus) */
.firma-split.solo { grid-template-columns: 1fr; }
.firma-split.solo .kontakt-side { display: none; }
.firma-kontakt-toggle { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; cursor: pointer; font-size: 12px; }
.firma-kontakt-toggle input { cursor: pointer; flex: none; align-self: center; }
.firma-kontakt-toggle .kt-label { font-weight: 600; }
.firma-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.firma-side .form-grid { gap: 10px 12px; }
/* Kompaktes Anlege-Formular – passt ohne vertikales Scrollen */
.firma-form .firma-suche { margin-bottom: 6px; }
.firma-form .firma-suche-status { margin-bottom: 10px; font-size: 11px; }
.firma-form .firma-side { gap: 7px; }
.firma-form .firma-side .form-grid { gap: 7px 12px; }
.firma-form .field { gap: 2px; }
.firma-form .field label { font-size: 11px; }
.firma-form .field input, .firma-form .field select { padding: 5px 9px; }
.firma-form .firma-side-hint { margin: -2px 0 2px; }
.firma-side + .firma-side { border-left: 1px solid var(--c-border); padding-left: 18px; }
.firma-side h4 { font-size: 13px; font-weight: 700; }
.firma-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.firma-side-hint { font-size: 11px; margin: -4px 0 2px; }
.seg { display: flex; gap: 10px; font-size: 12px; }
.seg label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }
.firma-quelle { margin-top: 4px; display: flex; flex-direction: column; gap: 3px; }
.quelle-row { font-size: 12px; display: flex; align-items: baseline; gap: 6px; }
.quelle-row .k { font-weight: 600; color: var(--c-text-soft); }
.quelle-row .url { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
@media (max-width: 680px) {
  .firma-split { grid-template-columns: 1fr; }
  .firma-side + .firma-side { border-left: none; padding-left: 0; border-top: 1px solid var(--c-border); padding-top: 14px; }
}

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--c-text-faint); padding: 32px 16px; font-size: 13px; }
.muted { color: var(--c-text-faint); }
.row-flex { display: flex; align-items: center; gap: 8px; }
.spread { display:flex; align-items:center; justify-content:space-between; gap:12px;}
.tag-list { display:flex; flex-wrap:wrap; gap:6px; }
.chip { display:inline-flex; align-items:center; gap:6px; padding:3px 8px; background:var(--c-bg); border:1px solid var(--c-border); border-radius:14px; font-size:12px;}
.chip .rm { cursor:pointer; color:var(--c-text-faint); font-weight:700;}
.chip .rm:hover{color:var(--danger);}
.avatar { width:30px;height:30px;border-radius:50%;background:var(--neutral-bg);color:var(--c-text-soft);display:inline-flex;align-items:center;justify-content:center;font-size:11px;font-weight:700;flex:none;}
.inline-edit-select { border:1px solid transparent; background:transparent; font-weight:600; border-radius:4px; padding:2px 4px; cursor:pointer; font-size:12px; color:inherit;}
.inline-edit-select:hover { border-color: var(--c-border-strong); background:#fff;}
hr.sep { border:none; border-top:1px solid var(--c-border); margin:14px 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display:flex; flex-direction:column; gap:8px; }
.toast { background:#2e3e4e; color:#fff; padding:10px 14px; border-radius:var(--radius); box-shadow:var(--shadow-pop); font-size:13px; max-width:340px; display:flex; gap:10px; align-items:flex-start; animation: slidein .18s ease; }
.toast.ok { border-left:3px solid var(--ok); }
.toast.info { border-left:3px solid var(--info); }
.toast.warn { border-left:3px solid var(--warn); }
.toast.err { border-left:3px solid var(--danger); }
.toast .t-act { color:var(--c-accent); font-weight:600; cursor:pointer; }
@keyframes slidein { from { transform: translateY(8px); opacity:0;} to { transform:none; opacity:1;} }

.loading { padding: 40px; text-align:center; color: var(--c-text-faint); }
.skeleton { background: linear-gradient(90deg,#eef2f6,#f6f9fb,#eef2f6); background-size:200% 100%; animation: sk 1.2s infinite; border-radius:4px; height:12px; }
@keyframes sk { from{background-position:200% 0;} to{background-position:-200% 0;} }

.filterbar { display:flex; gap:8px; align-items:center; margin-bottom:14px; flex-wrap:wrap; }
.filterbar select, .filterbar input { height:30px; border:1px solid var(--c-border-strong); border-radius:var(--radius); padding:0 8px; font-size:12px; background:#fff;}

/* ---------- Kontakthistorie (Zwei-Spalten / Inbox) ---------- */
.histo { display:grid; grid-template-columns: 320px 1fr; gap:16px; height: calc(100vh - 140px); min-height:420px; }
@media (max-width: 820px){ .histo{ grid-template-columns:1fr; height:auto; } }
.histo-pane { background:var(--c-surface); border:1px solid var(--c-border); border-radius:var(--radius); box-shadow:var(--shadow); display:flex; flex-direction:column; min-height:0; }
.histo-search { padding:10px; border-bottom:1px solid var(--c-border); }
.histo-search input { width:100%; height:32px; border:1px solid var(--c-border-strong); border-radius:var(--radius); padding:0 10px; font-size:13px; background:var(--c-bg); }
.histo-search input:focus { outline:none; border-color:var(--c-accent); background:#fff; }
.histo-list { overflow-y:auto; flex:1; min-height:0; }
.histo-contact { display:flex; gap:10px; padding:10px 12px; border-bottom:1px solid var(--c-border); cursor:pointer; align-items:flex-start; border-left:3px solid transparent; }
.histo-contact:hover { background:var(--c-bg); }
.histo-contact.active { background:#fff5f2; border-left-color:var(--c-accent); }
.histo-contact .hc-main { min-width:0; flex:1; }
.histo-contact .hc-top { display:flex; justify-content:space-between; gap:8px; align-items:baseline; }
.histo-contact .hc-name { font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.histo-contact .hc-time { font-size:11px; color:var(--c-text-faint); white-space:nowrap; flex:none; }
.histo-contact .hc-firma { font-size:12px; color:var(--c-text-soft); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.histo-contact .hc-snippet { font-size:12px; color:var(--c-text-faint); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:3px; display:flex; gap:6px; align-items:center; }
.histo-contact .hc-count { font-size:10px; font-weight:700; color:var(--c-text-faint); background:var(--neutral-bg); border-radius:10px; padding:1px 7px; flex:none; }
.histo-head { padding:12px 16px; border-bottom:1px solid var(--c-border); display:flex; justify-content:space-between; align-items:center; gap:10px; }
.histo-head h2 { font-size:16px; }
.histo-head .sub { font-size:12px; color:var(--c-text-soft); margin-top:1px; }
.histo-filter { display:flex; gap:6px; padding:8px 12px; border-bottom:1px solid var(--c-border); flex-wrap:wrap; align-items:center; }
.histo-filter .fp { font-size:12px; padding:3px 11px; border-radius:14px; border:1px solid var(--c-border-strong); background:#fff; cursor:pointer; color:var(--c-text-soft); }
.histo-filter .fp:hover { background:var(--c-bg); }
.histo-filter .fp.active { background:var(--c-accent); border-color:var(--c-accent); color:#fff; }
.histo-body { overflow-y:auto; flex:1; min-height:0; padding:6px 16px 16px; }
.histo-placeholder { display:flex; align-items:center; justify-content:center; height:100%; color:var(--c-text-faint); font-size:13px; padding:24px; text-align:center; }

/* ---------- Einstellungen ---------- */
.set-wrap { max-width: 820px; }
.set-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.set-head .desc { font-size:12px; color:var(--c-text-soft); margin-top:2px; }
.set-toggle { display:flex; align-items:center; gap:8px; font-size:12px; color:var(--c-text-soft); white-space:nowrap; }
.switch { position:relative; display:inline-block; width:38px; height:20px; flex:none; }
.switch input { opacity:0; width:0; height:0; }
.switch .slider { position:absolute; inset:0; background:var(--c-border-strong); border-radius:20px; transition:.15s; cursor:pointer; }
.switch .slider:before { content:''; position:absolute; height:14px; width:14px; left:3px; top:3px; background:#fff; border-radius:50%; transition:.15s; }
.switch input:checked + .slider { background:var(--ok); }
.switch input:checked + .slider:before { transform:translateX(18px); }
.webhook-url { display:flex; gap:8px; align-items:center; margin-top:6px; }
.webhook-url input { flex:1; font-family:ui-monospace,Menlo,monospace; font-size:12px; background:var(--c-bg); border:1px solid var(--c-border-strong); border-radius:var(--radius); padding:7px 10px; color:var(--c-text); }
.set-note { font-size:11px; color:var(--c-text-faint); margin-top:8px; }
.set-card-foot { display:flex; justify-content:flex-end; gap:8px; padding:12px 16px; border-top:1px solid var(--c-border); }

/* ---------- KI-Assistent (Topbar-Button + rechte Seitenleiste) ---------- */
.topbar .ki-toggle { gap:6px; }
.topbar .ki-toggle .ico { width:15px; height:15px; }
.topbar .ki-toggle.active { background:var(--c-accent); border-color:var(--c-accent); color:#fff; }

.ki-panel {
  position:fixed; top:0; right:0; height:100vh; width:var(--ki-w);
  background:var(--c-surface); border-left:1px solid var(--c-border);
  box-shadow:-8px 0 24px rgba(45,62,80,.10);
  display:flex; flex-direction:column; z-index:60;
  transform:translateX(100%); transition:transform .18s ease; will-change:transform;
}
body.ki-open .ki-panel { transform:translateX(0); }
/* Inhalt auf breiten Schirmen mitschieben, damit der Drawer nichts verdeckt */
@media (min-width:1180px){ body.ki-open .main { margin-right:var(--ki-w); } .main { transition:margin-right .18s ease; } }

.ki-head { display:flex; align-items:center; gap:8px; height:52px; padding:0 12px 0 14px; border-bottom:1px solid var(--c-border); flex:none; }
.ki-dot { width:8px; height:8px; border-radius:50%; background:var(--c-accent); box-shadow:0 0 0 3px #ffe9e2; flex:none; }
.ki-chatsel { flex:1; min-width:0; height:32px; border:1px solid var(--c-border-strong); border-radius:var(--radius); background:#fff; color:var(--c-text); font-size:13px; font-weight:600; padding:0 8px; cursor:pointer; }
.ki-chatsel:hover { border-color:var(--c-accent); }
.ki-chatsel:focus { outline:none; border-color:var(--c-accent); }
.ki-iconbtn { flex:none; border:1px solid transparent; background:transparent; color:var(--c-text-soft); font-size:18px; line-height:1; padding:4px 8px; border-radius:var(--radius); cursor:pointer; }
.ki-iconbtn:hover { background:var(--c-bg); color:var(--c-text); }

.ki-list { flex:1; overflow-y:auto; padding:14px; display:flex; flex-direction:column; gap:12px; }

.ki-empty { color:var(--c-text-soft); padding:8px 2px; }
.ki-empty-title { font-weight:600; color:var(--c-text); font-size:14px; }
.ki-empty-sub { font-size:12px; margin-top:4px; }

.ki-msg { display:flex; }
.ki-msg.user { justify-content:flex-end; }
.ki-msg.user .ki-bubble-body { background:var(--c-accent); color:#fff; border-radius:12px 12px 2px 12px; padding:8px 12px; max-width:85%; white-space:pre-wrap; }
.ki-msg.assistant .ki-bubble-body { background:var(--c-bg); color:var(--c-text); border:1px solid var(--c-border); border-radius:12px 12px 12px 2px; padding:10px 12px; max-width:100%; font-size:13px; }
.ki-msg.assistant.streaming .ki-bubble-body::after { content:'▍'; color:var(--c-accent); animation:ki-blink 1s steps(2) infinite; }
@keyframes ki-blink { 50% { opacity:0; } }

/* Markdown im Antwort-Bubble */
.ki-bubble-body p { margin:0 0 8px; }
.ki-bubble-body p:last-child, .ki-bubble-body ul:last-child, .ki-bubble-body ol:last-child, .ki-bubble-body table:last-child { margin-bottom:0; }
.ki-bubble-body ul, .ki-bubble-body ol { margin:0 0 8px; padding-left:18px; }
.ki-bubble-body li { margin:2px 0; }
.ki-bubble-body h3, .ki-bubble-body h4, .ki-bubble-body h5, .ki-bubble-body h6 { font-size:13px; margin:10px 0 4px; }
.ki-bubble-body code { font-family:ui-monospace,Menlo,monospace; font-size:12px; background:#eef2f7; border-radius:4px; padding:1px 5px; }
.ki-bubble-body pre { background:#2e3e4e; color:#e8eef5; border-radius:6px; padding:10px 12px; overflow-x:auto; margin:0 0 8px; }
.ki-bubble-body pre code { background:none; color:inherit; padding:0; }
.ki-bubble-body a { color:var(--c-link); }
table.ki-table { width:100%; border-collapse:collapse; font-size:12px; margin:0 0 8px; }
table.ki-table th, table.ki-table td { border:1px solid var(--c-border); padding:5px 8px; text-align:left; vertical-align:top; }
table.ki-table th { background:#fbfcfd; font-weight:600; color:var(--c-text-soft); }

.ki-status { flex:none; padding:6px 14px; font-size:11px; color:var(--c-text-soft); border-top:1px solid var(--c-border); background:var(--c-bg); display:flex; align-items:center; gap:6px; }
.ki-status::before { content:''; width:8px; height:8px; border-radius:50%; background:var(--c-accent); animation:ki-pulse 1s ease-in-out infinite; }
@keyframes ki-pulse { 0%,100% { opacity:.3; } 50% { opacity:1; } }

.ki-composer { flex:none; display:flex; gap:8px; align-items:flex-end; padding:12px 14px; border-top:1px solid var(--c-border); }
.ki-input { flex:1; resize:none; border:1px solid var(--c-border-strong); border-radius:var(--radius); padding:8px 10px; font-family:var(--font); font-size:13px; line-height:1.4; max-height:160px; color:var(--c-text); background:#fff; }
.ki-input:focus { outline:none; border-color:var(--c-accent); }
.ki-input:disabled { background:var(--c-bg); }
.ki-send { flex:none; height:34px; }

/* ---------- Übersicht: Firmen-Zeilen × Status-Spalten ---------- */
.ueb-scroll { overflow-x: auto; padding-bottom: 6px; }
.ueb-grid { --ueb-firm-w: 210px; display: grid; gap: 1px; background: var(--c-border); border: 1px solid var(--c-border); border-radius: 8px; min-width: 760px; }
.ueb-h { background: var(--c-bg); padding: 8px 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--c-text-soft); box-shadow: inset 0 -2px var(--neutral); }
.ueb-h.ueb-corner { box-shadow: none; }
.ueb-h[data-s="ok"] { box-shadow: inset 0 -2px var(--ok); }
.ueb-h[data-s="warn"] { box-shadow: inset 0 -2px var(--warn); }
.ueb-h[data-s="info"] { box-shadow: inset 0 -2px var(--info); }
.ueb-h[data-s="danger"] { box-shadow: inset 0 -2px var(--danger); }
.ueb-h[data-s="neutral"] { box-shadow: inset 0 -2px var(--neutral); }
.ueb-firm { background: #fff; padding: 10px; display: flex; flex-direction: column; gap: 3px; }
.ueb-firm.ohne { background: var(--c-bg); }
.uf-name { font-weight: 700; cursor: pointer; word-break: break-word; }
.uf-name:hover { color: var(--c-link); }
.ueb-firm.ohne .uf-name { cursor: default; color: var(--c-text-soft); }
.uf-sub { font-size: 11px; }
.uf-kontakt { font-size: 11px; margin-top: 2px; }
.uf-rolle { font-weight: 600; color: var(--c-text-soft); }
.ueb-cell { background: #fff; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-height: 46px; }
.ueb-proj { border: 1px solid var(--c-border); border-left: 3px solid var(--neutral); border-radius: 5px; padding: 6px 8px; cursor: pointer; background: #fff; box-shadow: var(--shadow); }
.ueb-proj:hover { border-color: var(--c-border-strong); }
.ueb-proj[data-s="ok"] { border-left-color: var(--ok); }
.ueb-proj[data-s="warn"] { border-left-color: var(--warn); }
.ueb-proj[data-s="info"] { border-left-color: var(--info); }
.ueb-proj[data-s="danger"] { border-left-color: var(--danger); }
.up-name { font-weight: 600; font-size: 12px; word-break: break-word; }
.up-meta { font-size: 11px; color: var(--c-text-soft); margin-top: 2px; }

/* ---------- Projekte: einfache Boxen ---------- */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.proj-box { background: #fff; border: 1px solid var(--c-border); border-radius: 8px; padding: 12px; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.proj-box:hover { border-color: var(--c-border-strong); }
.pb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pb-name { font-weight: 700; word-break: break-word; }
.pb-line { font-size: 12px; }
.pb-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--c-text-soft); }

/* ---------- Projekt: Beschreibung + KI-Auswertung ---------- */
textarea.beschreibung-input { width: 100%; min-height: 120px; resize: vertical; }
.aus-list-head { font-size: 12px; font-weight: 600; color: var(--c-text-soft); margin: 14px 0 8px; }
.aus-list { display: flex; flex-direction: column; gap: 8px; max-height: 42vh; overflow-y: auto; }
.aus-row { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--c-border); border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.aus-row:hover { border-color: var(--c-border-strong); }
.aus-row input[type=checkbox] { margin-top: 3px; flex: none; }
.aus-main { flex: 1; min-width: 0; }
.aus-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.aus-text { font-size: 13px; margin-top: 3px; }
.aus-meta { font-size: 11px; margin-top: 3px; }

/* ---------- Projekt-Übersicht: groß & volle Breite ---------- */
.proj-ueb { display: flex; flex-direction: column; gap: 16px; }
.proj-props { display: flex; flex-wrap: wrap; gap: 6px 26px; margin-bottom: 12px; }
.proj-props .prop { flex-direction: row; align-items: baseline; gap: 8px; padding: 0; border-bottom: none; }
textarea.beschreibung-input.gross { min-height: 320px; font-size: 14px; line-height: 1.55; }
.ki-eingabe-card { border-color: var(--c-accent); }
.ki-eingabe-card .card-head h3 { color: var(--c-accent-press); }
textarea.ki-eingabe-input { width: 100%; min-height: 96px; resize: vertical; line-height: 1.5; }
.ki-eingabe-status { font-size: 12px; }
