:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6c7484;
  --line: #dfe5ef;
  --blue: #2563eb;
  --green: #166534;
  --gold: #d4af37;
  --violet: #6d5dfc;
  --danger: #b42318;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  background: linear-gradient(180deg, #0b1020 0%, #151a2f 58%, #231f38 100%);
  color: #fff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #f5e7b2 100%);
  color: #111827;
  font-weight: 800;
}

.brand small,
.muted {
  color: var(--muted);
}

.company-tabs {
  display: grid;
  gap: 8px;
}

.company-tabs button,
.toolbar select,
.toolbar input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}

.company-tabs button {
  min-height: 42px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-align: left;
  cursor: pointer;
}

.company-tabs button.active {
  background: #fff;
  color: #101827;
}

.side-panel {
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.side-panel summary {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.side-panel summary::-webkit-details-marker {
  display: none;
}

.side-panel summary::after {
  content: "+";
  float: right;
  color: var(--gold);
}

.side-panel[open] summary::after {
  content: "-";
}

.side-panel p,
.side-panel li {
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  line-height: 1.5;
}

.side-panel ul {
  padding-left: 18px;
}

main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.toolbar input {
  width: min(42vw, 420px);
  padding: 11px 12px;
}

.toolbar select {
  padding: 11px 12px;
  background: #fff;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.metric,
.stage,
.table-wrap,
.detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric {
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--blue), var(--gold));
}

.metric small {
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stage {
  padding: 14px;
  min-height: 120px;
  max-height: 260px;
  overflow: auto;
}

.stage h2 {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 12px;
}

.pill {
  display: inline-flex;
  min-width: 28px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #edf2ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.stage-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
}

.stage-card strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.stage-card small {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 18px;
  align-items: start;
}

.table-wrap {
  overflow: hidden;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  list-style: none;
}

.section-head h2 {
  margin: 0;
}

.section-head::-webkit-details-marker {
  display: none;
}

.lead-scroll {
  max-height: 620px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: break-word;
}

th:nth-child(1),
td:nth-child(1) {
  width: 72px;
}

th:nth-child(2),
td:nth-child(2) {
  width: auto;
}

th:nth-child(3),
td:nth-child(3) {
  width: 132px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 190px;
}

th {
  color: var(--muted);
  font-size: 12px;
  background: #f9fbff;
  position: sticky;
  top: 0;
  z-index: 2;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f5f8ff;
}

.status {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef2f7;
  font-weight: 700;
  white-space: nowrap;
}

.status.ready_to_contact,
.status.meeting_ready {
  background: #e9f7ef;
  color: var(--green);
}

.status.do_not_contact,
.status.not_interested {
  background: #fff0ed;
  color: var(--danger);
}

.status.info_requested {
  background: #fff7e0;
  color: #8a6200;
}

.status.follow_up_1,
.status.follow_up_2,
.status.follow_up_3,
.status.contacted {
  background: #eef2ff;
  color: #3346a3;
}

.detail {
  padding: 18px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  overflow-wrap: anywhere;
}

.detail dl {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  font-size: 13px;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto auto;
  gap: 8px;
  margin: 16px 0;
}

.quick-actions label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.quick-actions select,
.quick-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  font-size: 13px;
  min-width: 0;
}

.quick-actions button {
  align-self: end;
  padding: 0 12px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}

.btn-report {
  background: var(--green) !important;
  font-weight: 700;
}

.btn-no-report {
  background: #e5e7eb !important;
  color: var(--muted) !important;
  cursor: not-allowed !important;
}

.report-badge {
  display: inline-flex;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--green);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
  vertical-align: middle;
  margin-left: 4px;
}

.detail dt {
  color: var(--muted);
}

.detail dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail a {
  color: var(--blue);
}

.company-chip {
  display: inline-flex;
  width: 36px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: #eef2ff;
  color: var(--blue);
  font-weight: 900;
  white-space: nowrap;
}

.lead-meta,
td .muted {
  display: block;
}

.lead-meta {
  margin: 3px 0 2px;
  color: #4b5563;
  font-size: 12px;
}

@media (max-width: 1100px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .metrics,
  .pipeline,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar,
  .toolbar {
    flex-direction: column;
    width: 100%;
  }

  .toolbar input,
  .toolbar select {
    width: 100%;
  }
}

/* ===== v2: Login ===== */
.login-overlay[hidden] {
  display: none;
}
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #0b1020 0%, #151a2f 58%, #231f38 100%);
}
.login-card {
  display: grid;
  gap: 12px;
  justify-items: center;
  background: var(--panel);
  border-radius: 14px;
  padding: 36px 44px;
  min-width: 320px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.login-card h2 { margin: 0; }
.login-card input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}
.login-card button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

/* ===== v2: Posteingang ===== */
.inbox-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.inbox-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 0;
}
.inbox-list {
  border-right: 1px solid var(--line);
  max-height: 480px;
  overflow: auto;
}
.inbox-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  gap: 3px;
}
.inbox-item:hover { background: #f5f8ff; }
.inbox-item.active { background: #eef2ff; }
.inbox-item.pending { border-left: 3px solid var(--gold); }
.inbox-item-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.inbox-item .cat { font-size: 11px; white-space: nowrap; }
.inbox-detail { padding: 18px; max-height: 480px; overflow: auto; }
.mail-body {
  background: #f9fbff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font-size: 13px;
  white-space: pre-wrap;
  max-height: 160px;
  overflow: auto;
  margin-bottom: 14px;
}
.draft-label { display: grid; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.draft-label input, #draftBody {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
}
#draftBody { resize: vertical; }
.draft-actions { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.btn-send {
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.btn-send:disabled { opacity: 0.6; cursor: wait; }
.btn-dismiss {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}
.sent-banner {
  background: #e9f7ef;
  color: var(--green);
  border-radius: 6px;
  padding: 12px;
  font-weight: 700;
}
.pad { padding: 14px; }

/* ===== v2: Lead-Detail Erweiterungen ===== */
.next-action-edit, .notes-edit { display: grid; gap: 6px; margin: 14px 0; }
.next-action-edit label, .notes-edit label { font-size: 12px; font-weight: 700; color: var(--muted); display: grid; gap: 4px; }
.next-action-edit input, .notes-edit textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
}
.next-action-edit button, .notes-edit button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  justify-self: start;
  padding: 0 14px;
}
.timeline { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.timeline h3 { font-size: 14px; margin-bottom: 10px; }
.timeline-item { margin-bottom: 10px; }
.timeline-item small { color: var(--muted); }
.timeline-item p { margin: 2px 0 0; font-size: 13px; }

/* ===== v2: Aktivität ===== */
.activity-wrap { margin-top: 18px; }
.activity { list-style: none; margin: 0; padding: 8px 16px 16px; max-height: 320px; overflow: auto; }
.activity li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.activity li small { color: var(--muted); margin-right: 8px; }
.event-type {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3346a3;
  font-size: 11px;
  font-weight: 800;
  margin-right: 6px;
}
.status.replied { background: #fff7e0; color: #8a6200; }
.status.new { background: #eef2f7; }

@media (max-width: 1100px) {
  .inbox-grid { grid-template-columns: 1fr; }
  .inbox-list { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ===== v2.1: Analysen & Dokumente ===== */
.documents { margin: 16px 0; border-top: 1px solid var(--line); padding-top: 12px; }
.documents h3 { font-size: 14px; margin-bottom: 10px; }
.doc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
  flex-wrap: wrap;
}
.doc-type {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3346a3;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.doc-webseiten-analyse { background: #e9f7ef; color: var(--green); }
.doc-entscheider-analyse { background: #fff7e0; color: #8a6200; }
.doc-neue-webseite { background: #f3e8ff; color: #6d28d9; }
.doc-angebot { background: #ffe9e0; color: #b45309; }
.doc-title { flex: 1; min-width: 120px; overflow-wrap: anywhere; }
.doc-open {
  color: #fff !important;
  background: var(--blue);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}
