/* Modul CRM – Stile (siehe docs/CRM.md §4). Präfix crm-. Nur Tokens aus theme.css. Mobile first. */

/* ------------------------------------------------------------------ Allgemein */
.crm-page { gap: 14px; }
.crm-page .card { overflow: hidden; } /* Zeilen bis an den Rand; Menüs/Modals sind fixed und werden nicht abgeschnitten */
.crm-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1;
}
.chip.is-active .crm-count { background: var(--brand); color: var(--brand-contrast); }
.crm-chip-alert .crm-count { background: var(--danger); color: var(--danger-contrast); }
.crm-tone-danger { color: var(--danger); font-weight: 600; }
.crm-tone-warning { color: var(--warning); font-weight: 600; }
.crm-tone-sage { color: var(--sage); font-weight: 600; }
.badge-sage { background: var(--sage-soft); color: var(--sage); }
.crm-pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.crm-empty-line { margin: 0; }
.crm-modal-lead { margin: 0; }
.crm-person { display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.crm-inline-link {
  border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--brand); cursor: pointer;
}
.crm-inline-link:hover { text-decoration: underline; }
.crm-card-link, .crm-more-link {
  display: inline-flex; align-items: center; gap: 2px; min-height: 32px; font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
}
.crm-more-link { margin-top: 10px; }
/* Lange Firmennamen («Bericht für Bundesamt für …»): Name mit «…», Pfeil bleibt sichtbar */
.crm-more-link { max-width: 100%; min-width: 0; }
@media (min-width: 900px) { .crm-hide-desktop { display: none !important; } }
@media (max-width: 899px) { .crm-hide-mobile { display: none !important; } }

/* Breiter Inhalt für die Kanban-Ansicht (viele Phasen) */
@media (min-width: 900px) { .content:has(> .crm-wide) { max-width: 1480px; } }

/* ------------------------------------------------------------------ Unter-Navigation */
.crm-nav {
  position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top)); z-index: 20;
  display: flex; align-items: center; gap: 4px;
  margin: -16px -14px 0; padding: 4px 4px 4px 10px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
/* Such-Sheet liegt in der (sticky) Leiste – dann muss diese über Kopfzeile und Tab-Leiste liegen */
.crm-nav:has(.modal-backdrop) { z-index: 150; }
.crm-nav-links {
  display: flex; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.crm-nav-links::-webkit-scrollbar { display: none; }
/* Weitere Einträge links/rechts ausserhalb des Bildes: Rand ausblenden (Klassen setzt CrmNav je nach Scrollposition) */
.crm-nav-links.is-more-left { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 22px); mask-image: linear-gradient(to right, transparent 0, #000 22px); }
.crm-nav-links.is-more-right { -webkit-mask-image: linear-gradient(to left, transparent 0, #000 28px); mask-image: linear-gradient(to left, transparent 0, #000 28px); }
.crm-nav-links.is-more-left.is-more-right {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 22px, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 22px, #000 calc(100% - 28px), transparent 100%);
}
.crm-nav-link {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 12px; border-radius: 999px;
  color: var(--text-muted); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; text-decoration: none !important;
}
.crm-nav-link .icon { display: none; }
.crm-nav-link:hover { background: var(--surface-2); color: var(--text); }
.crm-nav-link.is-active { background: var(--brand-soft); color: var(--brand-strong); }
.crm-nav-search { flex: none; }
@media (max-width: 899px) {
  .crm-nav-link { padding: 0 10px; }
  /* Querformat mit Notch: Leiste bis an den Rand wie Kopf- und Tab-Leiste, Inhalt innerhalb des sicheren Bereichs */
  .crm-nav {
    margin: -16px calc(-1 * max(14px, env(safe-area-inset-right))) 0 calc(-1 * max(14px, env(safe-area-inset-left)));
    padding: 4px max(4px, env(safe-area-inset-right)) 4px max(10px, env(safe-area-inset-left));
  }
}
@media (min-width: 900px) {
  .crm-nav { position: static; margin: -6px 0 0; padding: 0 0 10px; background: none; }
  .crm-nav-link { min-height: 36px; padding: 0 12px 0 10px; font-size: var(--fs); }
  .crm-nav-link .icon { display: inline-block; color: var(--text-faint); }
  .crm-nav-link.is-active .icon { color: var(--brand); }
}

/* ------------------------------------------------------------------ Suche */
.crm-search { position: relative; min-width: 0; }
.crm-search .input { padding-right: 40px; }
.crm-search-spin { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); display: inline-flex; }
.crm-search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50; padding: 4px;
  max-height: min(60vh, 480px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.crm-search-inline .crm-search-results { position: static; max-height: none; margin-top: 10px; padding: 0; border: 0; box-shadow: none; }
.crm-search-group + .crm-search-group { margin-top: 4px; }
.crm-search-item {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 8px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none !important;
}
.crm-search-item .icon { color: var(--text-muted); }
.crm-search-item:hover, .crm-search-item.is-active { background: var(--surface-2); }
.crm-search-item.is-active { box-shadow: inset 3px 0 0 var(--brand); }

/* ------------------------------------------------------------------ Übersicht */
.crm-hero { display: flex; flex-direction: column; gap: 12px; margin-top: -6px; }
.crm-quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.crm-quick-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 68px; padding: 8px 2px; min-width: 0;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm);
  font: inherit; font-size: var(--fs-sm); font-weight: 600; color: var(--text); cursor: pointer; white-space: nowrap;
}
@media (hover: hover) { .crm-quick-btn:hover { border-color: var(--brand); background: var(--brand-soft); } }
/* Eigener Schatten überschreibt sonst den Fokusring aus app.css */
.crm-quick-btn:focus-visible { box-shadow: var(--shadow-sm); }
.crm-quick-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); }
.crm-plus { color: var(--brand); font-weight: 700; }
@media (min-width: 900px) {
  .crm-hero { flex-direction: row; align-items: center; }
  .crm-hero .crm-search { flex: 1 1 auto; max-width: 520px; }
  .crm-quick { display: flex; flex-wrap: wrap; margin-left: auto; }
  .crm-quick-btn { flex-direction: row; min-height: 42px; padding: 4px 12px 4px 6px; gap: 8px; }
  .crm-quick-icon { width: 30px; height: 30px; }
}

.crm-kpi { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.crm-kpi-head { display: flex; align-items: center; gap: 6px; color: var(--text-faint); min-width: 0; }
.crm-kpi .stat-value { font-size: 19px; overflow-wrap: anywhere; }
/* Am Handy: Beschriftung darf umbrechen, Symbol entfällt (sonst «Gewonnen dies…»). Platz für zwei Zeilen, damit die
   Werte nebeneinander auf gleicher Höhe stehen; Wert etwas kleiner, damit «CHF 1'636'800.50» auf eine Zeile passt. */
@media (max-width: 719px) {
  .crm-kpi-head .icon { display: none; }
  .crm-kpi-head .stat-label { line-height: 1.3; min-height: 2.6em; }
  .crm-kpi .stat-value { font-size: clamp(14px, 4vw, 19px); }
}
@media (min-width: 720px) { .crm-kpi-head .stat-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }
@media (min-width: 900px) { .crm-kpi .stat-value { font-size: var(--fs-xl); } }

.crm-overview { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.crm-overview-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (min-width: 1100px) { .crm-overview { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); } }

/* Pipeline nach Phase (Balken) */
.crm-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.crm-bar-label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 5px; font-size: var(--fs-sm); font-weight: 600; min-width: 0; }
.crm-bar-num { flex: none; color: var(--text-muted); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.crm-bar-track { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.crm-bar-track > span { display: block; height: 100%; border-radius: inherit; background: var(--brand); transition: width .3s; }

/* ------------------------------------------------------------------ Aufgaben-Zeilen */
.crm-task-group + .crm-task-group { margin-top: 12px; }
.crm-list-more { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.crm-overdue-icon { margin-right: 4px; vertical-align: -2px; }
.crm-group-title {
  display: flex; align-items: center; gap: 6px; margin: 2px 0 2px; font-size: var(--fs-xs); font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint);
}
.crm-group-overdue > .crm-group-title { color: var(--danger); }
.crm-group-overdue > .crm-group-title .crm-count { background: var(--danger-soft); color: var(--danger); }
.crm-task-list { display: flex; flex-direction: column; }
.crm-task { display: flex; align-items: flex-start; gap: 2px; border-bottom: 1px solid var(--border); min-width: 0; }
.crm-task:last-child { border-bottom: 0; }
.crm-check {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; margin-left: -10px; padding: 0;
  border: 0; border-radius: 50%; background: none; cursor: pointer;
}
.crm-check:disabled { cursor: default; opacity: .6; }
.crm-check-box {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--surface); color: var(--success-contrast); transition: background .15s, border-color .15s;
}
.crm-check:hover:not(:disabled) .crm-check-box { border-color: var(--success); }
.crm-task.is-overdue .crm-check-box { border-color: var(--danger); }
.crm-task.is-done .crm-check-box { background: var(--success); border-color: var(--success); }
.crm-task-body {
  flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 11px 0 9px;
  border: 0; background: none; font: inherit; color: var(--text); text-align: left;
}
button.crm-task-body { cursor: pointer; min-height: var(--tap); }
.crm-task-title { display: flex; align-items: flex-start; gap: 7px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; hyphens: auto; }
/* Lange deutsche Wörter in schmalen Spalten mit Trennstrich umbrechen (lang="de-CH"); anywhere bleibt Rückfall */
.crm-card-title, .crm-card-company, .crm-tl-subject, .crm-row-title > .ellipsis { hyphens: auto; -webkit-hyphens: auto; hyphenate-limit-chars: 10 4 4; }
.crm-task-title > .icon { margin-top: 2px; color: var(--text-faint); }
.crm-task-open { align-self: flex-start; max-width: 100%; padding: 0; border: 0; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer; border-radius: var(--radius-sm); }
.crm-task-open:hover .crm-task-title > span { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.crm-task.is-done .crm-task-title > span { text-decoration: line-through; color: var(--text-muted); }
.crm-task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; font-size: var(--fs-sm); color: var(--text-muted); min-width: 0; padding-left: 22px; }
.crm-task > .menu { margin-top: 2px; }
.crm-due { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; white-space: nowrap; }
.crm-due.is-overdue { color: var(--danger); }
.crm-due.is-today { color: var(--brand); }
.crm-due-done { font-weight: 500; color: var(--text-muted); }
.crm-rel { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-width: 0; max-width: 100%; }
.crm-rel > * { display: inline-flex; align-items: flex-start; gap: 4px; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.crm-rel .icon { color: var(--text-faint); margin-top: 2px; } /* Symbol auf der ersten Zeile, wie beim Titel */
/* Handy (Bezüge als Text, Links im Menü): je Bezug eine Zeile mit «…» statt mehrzeiliger Namen */
.crm-rel-text .crm-rel-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-assignee { display: inline-flex; align-items: center; gap: 5px; }

/* Nächste Aktivität (Deal) */
.crm-next { display: inline-flex; align-items: center; gap: 5px; min-width: 0; max-width: 100%; font-size: var(--fs-xs); color: var(--text-muted); }
.crm-next.is-missing { color: var(--warning); font-weight: 600; }
.crm-next.is-overdue { color: var(--danger); font-weight: 600; }

/* ------------------------------------------------------------------ Zeilen in Karten (Deals, Projekte, Kontakte) */
.crm-rows { display: flex; flex-direction: column; margin: 0 -16px; }
.card > .crm-rows:last-child { margin-bottom: -16px; }
.crm-row {
  display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 16px; border-top: 1px solid var(--border);
  color: var(--text); text-decoration: none !important;
}
.crm-row:hover { background: var(--surface-2); }
.crm-row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.crm-row-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; }
.crm-row-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; min-width: 0; font-size: var(--fs-sm); color: var(--text-muted); }
.crm-row-end { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.crm-row-value { font-weight: 650; font-size: var(--fs-sm); }
.crm-row.is-closed .crm-row-title { color: var(--text-muted); }
@media (hover: hover) { a.crm-row:hover .crm-row-title > .ellipsis { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; } }

.crm-contact-line { display: flex; align-items: center; gap: 2px; padding: 4px 8px 4px 16px; border-top: 1px solid var(--border); }
.crm-contact-line:hover { background: var(--surface-2); }
.crm-contact-line.is-archived { opacity: .7; }
.crm-contact-main { flex: 1 1 auto; display: flex; align-items: center; gap: 10px; min-width: 0; min-height: var(--tap); color: var(--text); text-decoration: none !important; }

/* ------------------------------------------------------------------ Werkzeugleiste, Chips */
.crm-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; }
.crm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.crm-chips .chip { flex: none; }
@media (max-width: 899px) {
  .crm-chips-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
  .crm-chips-scroll::-webkit-scrollbar { display: none; }
}

/* ------------------------------------------------------------------ Listen (Firmen, Kontakte, Deals) */
.crm-list-head { display: none; }
.crm-list-row {
  display: flex; align-items: center; gap: 8px 10px; min-height: 62px; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none !important; min-width: 0;
}
.crm-list-row:last-child { border-bottom: 0; }
.crm-list-row:hover { background: var(--surface-2); }
.crm-list-row.is-archived .crm-row-title > .ellipsis, .crm-list-row.is-closed .crm-row-title > .ellipsis { color: var(--text-muted); }
@media (hover: hover) {
  a.crm-list-row:hover .crm-row-title > .ellipsis, .crm-row-link:hover .crm-row-title > .ellipsis {
    text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px;
  }
}
.crm-row-link { min-height: var(--tap); justify-content: center; color: var(--text); text-decoration: none !important; }
.crm-cell { display: none; min-width: 0; font-size: var(--fs-sm); }
.crm-list-row > .crm-row-end { flex-direction: row; gap: 0; }
.crm-list-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; padding: 10px 14px; background: var(--surface-2); font-size: var(--fs-sm); font-weight: 650; }
.crm-foot-sums { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px 14px; }
.crm-foot-sums > span { white-space: nowrap; }
.crm-foot-sums .muted { font-weight: 500; }
/* Deals am Handy: Titel links, Wert + Status rechts */
.crm-cols-deals.crm-list-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main value" "main badge"; }
.crm-cols-deals > .crm-row-main { grid-area: main; }
.crm-cols-deals > .crm-cell-value { grid-area: value; display: block; font-weight: 650; }
.crm-cols-deals > .crm-cell-badge { grid-area: badge; display: flex; justify-content: flex-end; }
@media (max-width: 899px) {
  .crm-row-title > .ellipsis { white-space: normal; overflow-wrap: anywhere; }
}
@media (min-width: 900px) {
  .crm-list-head {
    display: grid; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
    font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
  }
  .crm-list-head .num { text-align: right; }
  .crm-list-row { display: grid; gap: 10px; min-height: 56px; }
  .crm-cell { display: block; }
  .crm-cols-companies { grid-template-columns: minmax(0, 2.3fr) minmax(0, 1.2fr) 80px 150px 150px; }
  .crm-cols-contacts { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.3fr) minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1.5fr) 0; }
  .crm-cols-deals.crm-list-row, .crm-list-head.crm-cols-deals { grid-template-columns: minmax(0, 2.2fr) 170px 120px 110px minmax(0, 1.2fr); grid-template-areas: none; }
  .crm-cols-deals > * { grid-area: auto !important; }
  .crm-cols-deals > .crm-cell-badge { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; justify-content: center; }
  /* Verlustgrund: nicht breiter als die Zelle (sonst max-content über Wert/Abschluss/Verantwortlich), Badge bleibt schmal */
  .crm-cols-deals > .crm-cell-badge > .ellipsis { max-width: 100%; }
  .crm-cols-deals > .crm-cell-value { font-weight: 600; }
  .crm-list-row .crm-cell a { overflow: hidden; text-overflow: ellipsis; }
  /* Rechtsbündige Zahl, danach linksbündiges Datum: Abstand wie in .table (sonst «CHF 18'500 25.10.2026») */
  .crm-list-head > .num + :not(.num), .crm-list-row > .crm-cell.num + .crm-cell:not(.num) { padding-left: 14px; }
  /* Firmen: Name bis zwei Zeilen statt nach ~35 Zeichen abgeschnitten (Status steht in der Zeile darunter) */
  .crm-cols-companies .crm-row-title > .ellipsis {
    white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
}

/* ------------------------------------------------------------------ Pipeline */
/* Handy, Listen-Seiten: Titel/Untertitel neben «Neuer Deal» usw. (Untertitel bricht in seiner Spalte um, statt die
   Knöpfe in eine eigene Zeile zu schieben). Detailseiten behalten die Aktionen in voller Breite darunter. */
@media (max-width: 899px) {
  .crm-page:not(.crm-detail-page) > .page-header { flex-wrap: nowrap; }
  .crm-page:not(.crm-detail-page) > .page-header > .page-header-main { flex: 1 1 0; }
}

/* ------------------------------------------------------------------ Kanban */
.crm-board-jump { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
.crm-board-jump::-webkit-scrollbar { display: none; }
.crm-board-jump .chip { flex: none; }
.crm-board {
  display: flex; align-items: flex-start; gap: 12px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scroll-padding-inline: 14px; -webkit-overflow-scrolling: touch;
  margin: 0 -14px; padding: 2px 14px 14px;
}
/* Spalte ist eine vertiefte Fläche (im Dunkelmodus dunkler als die Karten, im Hellmodus grau unter weissen Karten) */
.crm-col {
  flex: 0 0 86%; max-width: 380px; min-width: 0; scroll-snap-align: start;
  display: flex; flex-direction: column; gap: 10px; padding: 10px;
  background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-lg);
  transition: background .12s, border-color .12s;
}
.crm-col.is-over { background: var(--brand-soft); border-color: var(--brand); }
.crm-col-head { display: flex; flex-direction: column; gap: 3px; padding: 2px 4px 8px; border-bottom: 2px solid var(--brand); }
.crm-col-orphan .crm-col-head { border-bottom-color: var(--border-strong); }
.crm-col-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crm-col-title h2 { flex: 1 1 auto; min-width: 0; font-size: var(--fs); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-col-meta { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.crm-col-sum { font-weight: 650; color: var(--text-muted); }
/*
 * Karten scrollen innerhalb der Spalte (wie Pipedrive/Trello): Spaltenkopf bleibt sichtbar, auch bei sehr ungleich
 * langen Phasen; nach einem Wisch zur nächsten Spalte steht man an deren Anfang. Padding/negativer Rand: Einfügemarke,
 * Schatten und Fokusring der Karten werden vom Scrollbereich nicht abgeschnitten.
 */
.crm-col-body {
  display: flex; flex-direction: column; gap: 10px; min-height: 64px;
  max-height: max(260px, calc(100dvh - var(--topbar-h) - env(safe-area-inset-top) - var(--tabbar-h) - env(safe-area-inset-bottom) - 214px));
  overflow-y: auto; scrollbar-width: thin; padding: 7px 4px 4px; margin: -7px -4px -4px;
}
.crm-col-more {
  min-height: var(--tap); padding: 4px 8px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: none;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; color: var(--brand); cursor: pointer; flex: none;
}
.crm-col-more:hover { background: var(--surface); }
.crm-col-body.is-drop-end::after { content: ''; display: block; height: 3px; margin: -4px 6px 0; border-radius: 2px; background: var(--brand); }
.crm-col-empty {
  margin: 0; padding: 18px 8px; text-align: center; font-size: var(--fs-sm); color: var(--text-faint);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.crm-col.is-over .crm-col-empty { display: none; }
.crm-col-add {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 4px 8px;
  border: 1px dashed transparent; border-radius: var(--radius); background: none;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); cursor: pointer;
}
.crm-col-add:hover { background: var(--surface); border-color: var(--border-strong); color: var(--brand); }

.crm-card {
  position: relative; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: box-shadow .12s, opacity .12s, border-color .12s;
}
.crm-card[draggable="true"] { cursor: grab; }
.crm-card[draggable="true"]:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
.crm-card.is-dragging { opacity: .4; }
.crm-card.is-drop-before::before {
  content: ''; position: absolute; left: 6px; right: 6px; top: -7px; height: 3px; border-radius: 2px; background: var(--brand);
}
.crm-card-main {
  display: flex; flex-direction: column; gap: 6px; min-height: var(--tap); padding: 10px 46px 10px 12px;
  color: var(--text); text-decoration: none !important; border-radius: inherit;
}
.crm-card-title { font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
@media (hover: hover) { .crm-card-main:hover .crm-card-title { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; } }
.crm-card-company { display: flex; align-items: flex-start; gap: 5px; min-width: 0; font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.crm-card-company .icon { color: var(--text-faint); margin-top: 2px; }
/* Wert + Datum umbrechen bei Bedarf untereinander; das Kürzel bleibt immer rechts auf der ersten Zeile */
.crm-card-facts { display: flex; align-items: flex-start; gap: 10px; font-size: var(--fs-sm); }
.crm-card-figs { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; padding-top: 2px; }
.crm-card-value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.crm-card-value.is-empty { font-weight: 400; color: var(--text-faint); }
.crm-card-date { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.crm-card-date.is-overdue { color: var(--danger); font-weight: 600; }
.crm-card-owner { flex: none; margin-left: auto; display: inline-flex; }
/* Rechter Innenabstand der Karte gehört dem ⋮-Knopf oben – die Kennzahlen-Zeile (unter der Firma) darf ihn nutzen */
.crm-card-main:has(.crm-card-company) .crm-card-facts { margin-right: -34px; }
.crm-card-menu { position: absolute; top: 2px; right: 2px; }

@media (min-width: 900px) {
  .crm-board { margin: 0; padding: 2px 2px 14px; scroll-snap-type: none; }
  .crm-col { flex: 1 0 200px; max-width: 340px; }
  .crm-col-body { max-height: max(320px, calc(100dvh - 190px)); }
  .crm-card-main { padding-right: 40px; }
  .crm-card-main:has(.crm-card-company) .crm-card-facts { margin-right: -28px; }
}

/* ------------------------------------------------------------------ Detailseiten */
.crm-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.crm-head-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: -10px; min-width: 0; }
@media (max-width: 899px) {
  .crm-detail-page .page-actions { width: 100%; }
  .crm-head-actions { width: 100%; }
  .crm-head-actions > .btn { flex: 1 1 0; min-width: 0; }
}

.crm-detail { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.crm-area-info { order: 1; }
.crm-area-contacts { order: 2; }
.crm-area-deals { order: 3; }
.crm-area-main { order: 4; }
.crm-area-time { order: 5; }
@media (min-width: 1100px) {
  .crm-detail {
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    grid-template-areas: "info main" "contacts main" "deals main" "time main" ". main";
    grid-template-rows: auto auto auto auto 1fr;
  }
  .crm-detail-contact { grid-template-areas: "info main" "deals main" ". main"; grid-template-rows: auto auto 1fr; }
  .crm-detail-deal { grid-template-areas: "info main" ". main"; grid-template-rows: auto 1fr; }
  .crm-area-info { grid-area: info; }
  .crm-area-contacts { grid-area: contacts; }
  .crm-area-deals { grid-area: deals; }
  .crm-area-time { grid-area: time; }
  .crm-area-main { grid-area: main; }
}

/* Stammdaten: ein Raster für alle Zeilen – Beschriftungsspalte so breit wie nötig (längstes Wort), höchstens ~150 px */
.crm-info { margin: 0; display: grid; grid-template-columns: fit-content(164px) minmax(0, 1fr); }
.crm-info-row { display: contents; }
.crm-info dt, .crm-info dd { display: flex; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--border); min-width: 0; }
.crm-info-row:first-child > * { border-top: 0; padding-top: 0; }
.crm-info-row:last-child > * { padding-bottom: 0; }
.crm-info dt { gap: 7px; font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.3; padding-top: 10px; padding-right: 14px; } /* statt column-gap: Trennlinien laufen durch */
.crm-info-row:first-child > dt { padding-top: 2px; }
.crm-info dt .icon { color: var(--text-faint); margin-top: 1px; }
.crm-info dd { margin: 0; flex-wrap: wrap; overflow-wrap: anywhere; }
.crm-info dd a { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; overflow-wrap: anywhere; }

/* Zeiterfassung der Firma */
.crm-time { display: flex; flex-direction: column; gap: 12px; }
.crm-time-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
.crm-time-facts dt { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.crm-time-facts dd { margin: 2px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.crm-mini-list { list-style: none; margin: 0; padding: 0; }
.crm-mini-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.crm-time .crm-more-link { margin-top: 0; }

/* Deal */
.crm-deal-hero { display: flex; flex-direction: column; gap: 16px; }
.crm-deal-hero.is-won { border-color: var(--sage); }
.crm-deal-hero.is-lost { border-color: var(--danger); }
.crm-deal-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.crm-deal-figures > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.crm-deal-value { font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.crm-deal-sub { font-weight: 600; font-variant-numeric: tabular-nums; padding-top: 4px; overflow-wrap: anywhere; }
/* Handy: Wert über die ganze Breite (sonst «CHF» / «1'250'000» untereinander), Gewichtet/Abschluss darunter */
@media (max-width: 479px) {
  .crm-deal-figures { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 12px; }
  .crm-deal-figures > :first-child { grid-column: 1 / -1; }
  .crm-deal-value { font-size: var(--fs-lg); } .crm-deal-sub { padding-top: 3px; }
}
.crm-stages { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; }
.crm-stage-li { flex: 1 1 0; min-width: 0; }
.crm-stage {
  width: 100%; min-height: var(--tap); display: flex; flex-direction: column; gap: 6px; padding: 6px 2px 4px;
  border: 0; border-radius: var(--radius-sm); background: none; font: inherit; font-size: var(--fs-sm); color: var(--text-muted); text-align: left; cursor: pointer;
}
.crm-stage[aria-disabled="true"] { cursor: progress; } /* statt disabled: der gedrückte Knopf behält den Fokus */
.crm-stage-bar { display: block; height: 8px; border-radius: 999px; background: var(--surface-3); transition: background .15s; }
.crm-stage.is-done .crm-stage-bar { background: var(--brand); opacity: .55; }
.crm-stage.is-current .crm-stage-bar { background: var(--brand); }
.crm-stage.is-current { color: var(--text); font-weight: 650; }
.crm-stage:hover:not([aria-disabled="true"]) .crm-stage-bar { box-shadow: 0 0 0 2px var(--brand-soft), 0 0 0 3px var(--brand); }
.crm-stage > .crm-stage-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-stage-current { display: none; margin: -8px 0 0; font-size: var(--fs-sm); color: var(--text-muted); }
/* Schmale Handys: Namen in den Segmenten würden abgeschnitten («Verhandl…») – stattdessen eine Zeile darunter.
   Die Namen bleiben für Screenreader im Knopf (visuell versteckt). */
@media (max-width: 479px) {
  .crm-stage > .crm-stage-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .crm-stage { justify-content: center; }
  .crm-stage-current { display: block; }
}
.crm-deal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.crm-deal-actions > .btn { flex: 1 1 130px; }
.crm-deal-next { flex: 1 1 100%; min-width: 0; }
@media (min-width: 700px) {
  .crm-deal-actions > .btn { flex: none; min-width: 140px; }
  .crm-deal-next { flex: 1 1 auto; display: flex; justify-content: flex-end; }
}
.btn-sage { background: var(--sage); color: var(--brand-contrast); }
.btn-sage:hover:not(:disabled) { filter: brightness(.94); }
.crm-btn-lost { color: var(--danger); }
.crm-outcome { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 12px; padding: 12px 14px; border-radius: var(--radius); }
.crm-outcome > .icon { margin-top: 1px; }
.crm-outcome-won { background: var(--sage-soft); color: var(--sage); }
.crm-outcome-lost { background: var(--danger-soft); color: var(--danger); }
.crm-outcome-text { flex: 1 1 220px; display: flex; flex-direction: column; gap: 2px; min-width: 0; color: var(--text); }
.crm-outcome-won .crm-outcome-text strong { color: var(--sage); }
.crm-outcome-lost .crm-outcome-text strong { color: var(--danger); }
.crm-outcome-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------------ Zeitachse */
.crm-timeline { display: flex; flex-direction: column; gap: 18px; }
.crm-tl-head { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.crm-tl { list-style: none; margin: 0; padding: 0; }
.crm-tl-item { position: relative; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; padding-bottom: 16px; }
.crm-tl-item:last-child { padding-bottom: 0; }
.crm-tl-item::before { content: ''; position: absolute; left: 15px; top: 36px; bottom: 2px; width: 2px; border-radius: 1px; background: var(--border); }
.crm-tl-item:last-child::before { display: none; }
.crm-tl-icon { display: grid; place-items: center; width: 32px; height: 32px; margin-top: 2px; border-radius: 50%; background: var(--surface-3); color: var(--text-muted); }
.crm-type-note .crm-tl-icon { background: var(--warning-soft); color: var(--warning); }
.crm-type-call .crm-tl-icon { background: var(--info-soft); color: var(--info); }
.crm-type-meeting .crm-tl-icon { background: var(--brand-soft); color: var(--brand); }
.crm-type-email .crm-tl-icon { background: var(--sage-soft); color: var(--sage); }
.crm-type-task .crm-tl-icon { background: var(--success-soft); color: var(--success); }
.crm-tl-body { min-width: 0; }
.crm-tl-top { display: flex; align-items: flex-start; gap: 4px; }
.crm-tl-top > .menu { margin-bottom: -12px; } /* Menü-Knopf soll die Metazeile nicht nach unten drücken */
.crm-tl-text { flex: 1 1 auto; min-width: 0; padding-top: 7px; }
.crm-type-note .crm-tl-text { padding: 8px 11px; border-radius: var(--radius-sm); background: var(--surface-2); }
.crm-tl-subject { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.crm-tl-note { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.crm-type-note .crm-tl-note { margin: 0; }
.crm-tl-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin-top: 5px; font-size: var(--fs-xs); color: var(--text-muted); }
.crm-tl-meta > :not(:first-child)::before { content: '·'; margin-right: 6px; color: var(--text-faint); }
/* Bezüge immer auf eigener Zeile und ohne Trennpunkt – sonst beginnt die umgebrochene Zeile mit einem einzelnen «·» */
.crm-tl-meta > .crm-rel { flex-basis: 100%; gap: 2px 10px; }
.crm-tl-meta > .crm-rel::before { content: none; }

/* Eingabe */
.crm-composer { display: flex; flex-direction: column; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.crm-composer-tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.crm-composer-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; min-height: var(--tap); padding: 4px 2px;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: none;
  font: inherit; font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); cursor: pointer;
}
.crm-composer-tab > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-composer-tab:hover { color: var(--text); }
.crm-composer-tab.is-active { background: var(--surface); border-color: var(--border-strong); color: var(--brand-strong); box-shadow: var(--shadow-sm); }
.crm-composer-tab.is-active:focus-visible { box-shadow: var(--shadow-sm); }
.crm-composer-tab.is-active .icon { color: var(--brand); }
/* Sehr schmale Handys (≤ 380 px): fünf Spalten sind zu eng für «Aufgabe»/«Meeting» – weniger Abstand, sonst «Aufg…» */
@media (max-width: 380px) {
  .crm-composer-tabs { gap: 2px; }
  .crm-composer-tab { padding-left: 0; padding-right: 0; font-size: 11.5px; letter-spacing: -.01em; }
}
@media (min-width: 600px) { .crm-composer-tab { flex-direction: row; gap: 6px; min-height: 36px; font-size: var(--fs-sm); } }
@media (pointer: coarse) { .crm-composer-tab { min-height: var(--tap); } }
.crm-composer-note .field-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.crm-composer .segmented { align-self: flex-start; background: var(--surface); }
.crm-composer-foot { display: flex; justify-content: flex-end; }
.crm-due-row { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; }
.crm-due-row > :nth-child(3) { grid-column: 1 / -1; }
@media (min-width: 600px) {
  .crm-due-row { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr) minmax(0, 1.4fr); }
  .crm-due-row > :nth-child(3) { grid-column: auto; }
}

/* ------------------------------------------------------------------ Formulare */
.crm-fieldset { display: flex; flex-direction: column; gap: 12px; min-width: 0; margin: 4px 0 0; padding: 10px 12px 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.crm-fieldset legend { display: flex; align-items: center; gap: 6px; padding: 0 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.crm-stage-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.crm-stage-edit { display: grid; grid-template-columns: auto minmax(0, 1fr) 84px auto; align-items: center; gap: 6px; }
.crm-stage-move { display: flex; }
.crm-stage-move .btn-icon:disabled { opacity: .25; }
.crm-stage-edit.has-error .crm-stage-name { border-color: var(--danger); }
.crm-stage-err { grid-column: 1 / -1; }
/* Handy: Name auf eigener, ganzer Zeile (sonst nur ~100 px – «Verhandlu…»); darunter ▲▼, % und Entfernen */
@media (max-width: 599px) {
  .crm-stage-edit { grid-template-columns: auto minmax(0, 1fr) auto; row-gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  .crm-stage-edit:last-child { border-bottom: 0; padding-bottom: 0; }
  .crm-stage-edit > .crm-stage-name { grid-row: 1; grid-column: 1 / -1; }
  .crm-stage-pct { justify-self: start; width: 112px; }
}
@media (min-width: 600px) { .crm-stage-edit { grid-template-columns: auto minmax(0, 1fr) 100px auto; } }

/* ------------------------------------------------------------------ Touch-Ziele ≥ 44 px (Handy, Touch) */
@media (max-width: 899px), (pointer: coarse) {
  /* app.css setzt .input erst nach der Touch-Regel auf 42 px – hier für alle CRM-Seiten samt ihrer Modals */
  .crm-page .input, .crm-page .picker { min-height: var(--tap); }
  .crm-card-link, .crm-more-link, .crm-inline-link { min-height: var(--tap); }
  .crm-card-link { min-width: var(--tap); justify-content: center; padding: 0 4px; }
  .crm-inline-link { display: inline-flex; align-items: center; }
  /* Beschriftung und Wert oben bündig (nicht zentriert: bei mehrzeiligen Werten stünde «Notizen» mitten im Text).
     Links behalten 44 px Höhe, ihr Text steht oben wie bei reinen Textwerten. */
  .crm-info dd a { min-height: var(--tap); align-items: flex-start; }
  .crm-info dt, .crm-info dd { align-items: flex-start; padding-top: 4px; padding-bottom: 4px; }
  .crm-info dt { padding-top: 6px; }
  .crm-info-row:first-child > * { padding-top: 0; }
  .crm-info-row:first-child > dt { padding-top: 2px; }
  .crm-outcome-text a { display: inline-flex; align-items: center; min-height: var(--tap); }
  .crm-page .segmented-item { min-height: var(--tap); padding-left: 12px; padding-right: 12px; }
  .crm-page .toggle, .crm-modal .toggle { min-height: var(--tap); }
}
