:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --brand: #1f2937;
  --brand-hover: #374151;
  --accent: #2563eb;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--brand);
  color: #fff;
  padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left));
  box-shadow: var(--shadow);
}

.header-title {
  color: #fff;
  font-weight: 600;
  font-size: 1.1rem;
}

.menu-toggle {
  background: transparent;
  color: #fff;
  border: 0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 0.25rem;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 240px;
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}
.sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 15;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }

.nav-link {
  display: block;
  padding: 0.75rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--bg); text-decoration: none; }

.nav-spacer { flex: 1; }
.nav-user { padding: 0.75rem 1.25rem; color: var(--muted); font-size: 0.9rem; }
.nav-logout { margin: 0; }
.nav-logout-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  font: inherit;
  cursor: pointer;
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

.main {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.main--wide { max-width: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

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

h1, h2 { margin-top: 0; }

.module-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.module-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.module-card:hover {
  border-color: var(--brand);
  text-decoration: none;
  transform: translateY(-1px);
}
.module-card h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.module-card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-title {
  margin: 0 0 1.25rem;
  text-align: center;
  font-size: 1.5rem;
}

.form-group { margin-bottom: 1rem; }
.form-label { display: block; margin-bottom: 0.25rem; font-size: 0.9rem; color: var(--muted); }
.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: max(1rem, 16px);
  background: #fff;
}
select.form-input,
textarea.form-input { font-size: max(1rem, 16px); }
.form-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  font: inherit;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}
.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-block { display: block; width: 100%; margin-top: 0.5rem; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: var(--error-bg); color: var(--error-text); }

/* === Hours module === */

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}
.subnav-link {
  padding: 0.35rem 0.75rem;
  color: var(--muted);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.subnav-link:hover { background: var(--bg); text-decoration: none; }
.subnav-link.active { background: var(--brand); color: #fff; }

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}
.stat-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.5rem; font-weight: 600; margin-top: 0.25rem; }
.stat-sub { color: var(--muted); font-size: 1rem; font-weight: 400; }

.entry-textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  resize: vertical;
}

.form-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.form-hint { color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0 0; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-link { background: transparent; border: 0; color: var(--accent); cursor: pointer; padding: 0.2rem 0.4rem; font: inherit; }
.btn-link:hover { text-decoration: underline; }

.message { margin-top: 0.75rem; font-size: 0.9rem; }
.message.success { color: #065f46; background: #d1fae5; padding: 0.5rem 0.75rem; border-radius: var(--radius); }
.message.error { color: var(--error-text); background: var(--error-bg); padding: 0.5rem 0.75rem; border-radius: var(--radius); }
.message-details { margin: 0.5rem 0 0 1.25rem; font-size: 0.85rem; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-left: -0.25rem;
  margin-right: -0.25rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

.entries-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.entries-table th, .entries-table td {
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.entries-table th { font-weight: 600; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; }
.entries-table thead th[data-sort-key] { cursor: pointer; user-select: none; white-space: nowrap; }
.entries-table thead th[data-sort-key]:hover { color: var(--text); }
.entries-table thead th[data-sort-key] .sort-indicator::before { content: ' '; opacity: 0.4; margin-left: 0.25rem; }
.entries-table thead th[data-sort-key][aria-sort="ascending"] .sort-indicator::before { content: ' \25B2'; opacity: 1; }
.entries-table thead th[data-sort-key][aria-sort="descending"] .sort-indicator::before { content: ' \25BC'; opacity: 1; }
.entries-table thead th[data-sort-key][aria-sort] { color: var(--text); }
.entries-table tr.inactive { opacity: 0.6; }
.entry-date { white-space: nowrap; color: var(--muted); }
.entry-customer { font-weight: 500; }
.entry-customer.break { color: var(--muted); font-style: italic; }
.entry-hours { white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry-desc { }
.entry-actions { text-align: right; white-space: nowrap; }

.customer-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.weekly-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.weekly-row:last-child { border-bottom: 0; }
.weekly-label { font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.weekly-bar-bg { background: var(--bg); border-radius: 4px; overflow: hidden; height: 12px; }
.weekly-bar { height: 100%; transition: width 0.3s ease; }
.weekly-bar-low { background: #ef4444; }
.weekly-bar-good { background: #f59e0b; }
.weekly-bar-complete { background: #10b981; }
.weekly-numbers { font-variant-numeric: tabular-nums; font-size: 0.9rem; white-space: nowrap; }

.cust-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.3rem 0;
}
.cust-label { font-size: 0.9rem; }
.cust-bar-bg { background: var(--bg); border-radius: 4px; height: 10px; overflow: hidden; }
.cust-bar { height: 100%; }
.cust-numbers { font-size: 0.9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.85rem; background: var(--border); }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* Calendar */
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekday { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; text-align: center; padding: 0.25rem; }
.cal-cell { border: 1px solid var(--border); border-radius: 4px; min-height: 70px; padding: 0.3rem; display: flex; flex-direction: column; }
.cal-blank { border: 1px dashed var(--border); background: transparent; }
.cal-num { font-size: 0.85rem; color: var(--muted); }
.cal-hours { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 0.85rem; margin: auto 0; }
.cal-meter { background: var(--bg); border-radius: 3px; height: 4px; overflow: hidden; margin-top: auto; }
.cal-fill { height: 100%; background: var(--accent); }
.cal-full .cal-fill { background: #10b981; }
.cal-partial .cal-fill { background: #f59e0b; }

/* Timer */
.timer-display {
  font-size: 3rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
  font-variant-numeric: tabular-nums;
  margin: 1rem 0;
  color: var(--brand);
  transition: color 0.2s ease, opacity 0.2s ease;
}
.timer-display-paused { color: var(--muted); opacity: 0.6; }
.timer-form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 480px; margin: 0 auto; width: 100%; }
.timer-state {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.timer-state-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: currentColor;
}
.timer-state.badge-success .timer-state-dot { animation: timer-pulse 1.6s ease-in-out infinite; }
@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Einstellungen customer rows */
.customer-row {
  display: grid;
  grid-template-columns: 44px minmax(160px, 320px) auto auto auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.customer-row:last-child { border-bottom: 0; }
.customer-color { width: 40px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.customer-toggle { display: flex; align-items: center; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.customer-count { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.customer-delete { color: var(--danger, #b91c1c); }

/* Edit dialog */
.edit-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 420px;
  width: 92%;
}
.edit-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.edit-dialog form { display: flex; flex-direction: column; gap: 0.75rem; }

.small { font-size: 0.8rem; }

@media (max-width: 640px) {
  .weekly-row { grid-template-columns: 80px 1fr auto; font-size: 0.8rem; }
  .cust-row { grid-template-columns: 100px 1fr auto; font-size: 0.85rem; }
  .entries-table { font-size: 0.8rem; }
  .entries-table th, .entries-table td { padding: 0.35rem 0.3rem; }
  .cal-cell { min-height: 50px; padding: 0.2rem; }
  .cal-num { font-size: 0.7rem; }
  .cal-hours { font-size: 0.75rem; }

  .form-row > * { flex: 1 1 100%; min-width: 0; }

  .customer-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }
  .customer-color { flex: 0 0 44px; width: 44px; height: 44px; }
  .customer-row .form-input { flex: 1 1 180px; min-width: 0; }
  .customer-row .customer-toggle { flex: 1 1 100%; }
  .customer-row .customer-count { flex: 1 1 auto; }

  .btn-link {
    padding: 0.6rem 0.6rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .menu-toggle {
    padding: 0.5rem 0.75rem;
    min-height: 44px;
    min-width: 44px;
  }
  .subnav-link { padding: 0.5rem 0.85rem; }
  .tag-item { padding: 0.35rem 0.65rem; }
  .nav-link { padding: 0.9rem 1.25rem; }
}

/* === Lesezeichen module === */

.subnav-badge {
  padding: 0.35rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--muted);
}
.subnav-clear { margin-left: 0.3rem; text-decoration: none; color: var(--muted); font-weight: bold; }
.subnav-clear:hover { color: var(--text); text-decoration: none; }

.bm-search { display: flex; gap: 0.5rem; }
.bm-search input { flex: 1; }

.bm-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.bm-sidebar { position: sticky; top: 60px; max-height: calc(100vh - 80px); max-height: calc(100dvh - 80px); overflow-y: auto; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
}
.tag-item:hover { border-color: var(--brand); text-decoration: none; }
.tag-item.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tag-item.active .tag-count { color: #d1d5db; }
.tag-count { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

.bm-list { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.75rem; }
.bookmark {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
}
.bm-line { display: flex; align-items: baseline; gap: 0.4rem; }
.bm-title { font-size: 1rem; font-weight: 500; color: var(--text); word-break: break-word; }
.bm-title:hover { text-decoration: underline; }
.bm-star { color: #f59e0b; }
.bm-toread { color: var(--muted); }

.bm-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.bm-domain { color: var(--accent); font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.8rem; }
.bm-tags { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; }
.bm-tag {
  padding: 0.1rem 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--text);
}
.bm-tag:hover { border-color: var(--brand); text-decoration: none; }
.bm-desc {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.4;
}

.form-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.form-check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }

@media (max-width: 800px) {
  .bm-layout { grid-template-columns: 1fr; }
  .bm-sidebar { position: static; max-height: none; }
}

@media (min-width: 900px) {
  .sidebar { transform: translateX(0); position: sticky; height: calc(100vh - 52px); height: calc(100dvh - 52px); width: 220px; }
  .menu-toggle { display: none; }
  .sidebar-backdrop { display: none; }
  body { display: grid; grid-template-rows: auto 1fr; grid-template-columns: 220px 1fr; }
  .header { grid-column: 1 / -1; }
  .sidebar { grid-column: 1; }
  .main { grid-column: 2; }
}

.eintraege-filter {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.5rem 1rem;
  align-items: end;
}
.eintraege-filter .form-actions { grid-column: 1 / -1; }

/* === CRM module === */

.stat-warn { color: #b91c1c; }

.crm-counts { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.crm-count-chip {
  padding: 0.2rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
}

.crm-chip {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid transparent;
}
.crm-chip-new { background: #e0e7ff; color: #3730a3; }
.crm-chip-contacted { background: #dbeafe; color: #1e40af; }
.crm-chip-interested { background: #d1fae5; color: #065f46; }
.crm-chip-not_interested { background: #fee2e2; color: #991b1b; }
.crm-chip-converted { background: #fef3c7; color: #92400e; }
.crm-chip-dormant { background: var(--bg); color: var(--muted); border-color: var(--border); }

.crm-chip-channel {
  padding: 0.1rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--muted);
}

.crm-section.crm-overdue { border-left: 4px solid #b91c1c; }
.crm-section.crm-today { border-left: 4px solid #f59e0b; }
.crm-section.crm-week { border-left: 4px solid var(--accent); }

.crm-followups {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.crm-followups li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 1rem;
  padding: 0.5rem;
  background: var(--bg);
  border-radius: var(--radius);
}
.crm-fu-main { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.crm-fu-contact { font-weight: 500; }
.crm-fu-proto { color: var(--muted); font-size: 0.85rem; }
.crm-fu-action { grid-column: 1 / -1; display: flex; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; font-size: 0.9rem; }
.crm-fu-text { color: var(--text); }
.crm-fu-date { color: var(--muted); font-size: 0.85rem; }
.crm-fu-buttons { display: flex; align-items: center; }

.crm-timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.crm-timeline li {
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
  border-left: 3px solid var(--border);
}
.crm-tp-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.2rem; }
.crm-tp-when { font-variant-numeric: tabular-nums; }
.crm-tp-proto { color: var(--accent); font-size: 0.85rem; }
.crm-tp-contact { font-weight: 500; margin-right: 0.5rem; }
.crm-tp-line { display: flex; gap: 0.5rem; align-items: baseline; }
.crm-tp-summary { font-weight: 500; }
.crm-tp-body { font-size: 0.9rem; color: var(--text); margin-top: 0.25rem; white-space: pre-wrap; }

/* Visual threading: any touchpoint with in_reply_to is indented + accented. */
.crm-timeline li.is-reply {
  margin-left: 1.75rem;
  border-left-color: var(--accent);
}
.crm-timeline li.is-reply::before {
  content: "↳ ";
  color: var(--muted);
  margin-right: 0.25rem;
  font-size: 0.85rem;
}

/* Reply context banner inside the compose form. */
.crm-reply-context {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--bg-subtle, #f5f5f5);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.crm-reply-context strong { font-weight: 500; }

.crm-contact-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.crm-contact-head h1 { margin: 0; }
.crm-contact-actions { display: flex; gap: 0.4rem; }
.crm-contact-info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  margin: 0.75rem 0 0.5rem;
  font-size: 0.9rem;
}
.crm-contact-info dt { color: var(--muted); }
.crm-contact-info dd { margin: 0; }
.crm-notes { margin-top: 0.5rem; white-space: pre-wrap; font-size: 0.9rem; padding: 0.5rem 0.75rem; background: var(--bg); border-radius: var(--radius); }

.crm-links { display: flex; flex-direction: column; gap: 0.75rem; }
.crm-link-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.crm-link-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.crm-link-head strong { flex: 1 1 auto; }
.crm-link-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.5rem; }
.crm-link-body .form-label.small { font-size: 0.8rem; }

.crm-add-link { display: flex; gap: 0.5rem; align-items: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.crm-add-link .form-label { flex: 1; }

.crm-link-arrow { color: var(--muted); font-weight: 600; }
.crm-links-subhead { font-size: 0.95rem; margin: 1rem 0 0.5rem; color: var(--muted); }
.crm-incoming-links { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; }
.crm-incoming-links li { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.crm-link-label { color: var(--muted); }

.crm-new-tp { margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }

.crm-email-compose { margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.crm-email-compose > summary { cursor: pointer; padding: 0.5rem 0; font-weight: 500; user-select: none; }
.crm-email-compose[open] > summary { margin-bottom: 0.75rem; }

.crm-email-save-template {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0;
}
.crm-email-save-template legend { color: var(--muted); font-size: 0.85rem; padding: 0 0.35rem; }
.form-label.inline { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.form-label.inline input[type="checkbox"] { width: auto; }

.crm-template-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.crm-template-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.crm-template-head { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
.crm-template-head .form-input { flex: 1 1 200px; }

.crm-filter { display: grid; grid-template-columns: minmax(180px, 320px) auto auto auto auto; gap: 0.5rem; align-items: center; }
.crm-contacts-table .crm-contact-name { font-weight: 500; }
.crm-proto-line { display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; font-size: 0.85rem; }
.crm-tags { display: flex; flex-wrap: wrap; gap: 0.2rem; margin-top: 0.25rem; }

.crm-initial-link {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-top: 1rem;
}
.crm-initial-link legend { color: var(--muted); font-size: 0.9rem; padding: 0 0.35rem; }

@media (max-width: 800px) {
  .crm-filter { grid-template-columns: 1fr; }
  .crm-followups li { grid-template-columns: 1fr; }
  .crm-link-body { grid-template-columns: 1fr; }
  .crm-add-link { flex-direction: column; align-items: stretch; }
}

/* === Werkstatt === */

.error-banner {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-text);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.empty-state { text-align: center; padding: 2rem 1rem; }
.empty-state .btn { margin-top: 1rem; }

.ws-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.ws-overview-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color 0.1s ease;
}
.ws-overview-card:hover { border-color: var(--accent); text-decoration: none; }
.ws-overview-card h3 { margin: 0 0 0.25rem; font-size: 1.05rem; }
.ws-overview-card p { margin: 0 0 0.75rem; font-size: 0.9rem; }
.ws-overview-counts { display: flex; flex-wrap: wrap; gap: 0.6rem; font-size: 0.85rem; }
.ws-counter {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-weight: 500;
}
.ws-counter-open { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }

.ws-archived-banner { background: #fef3c7; border-color: #fbbf24; color: #92400e; }

.ws-filters {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr) auto auto;
  gap: 0.5rem;
  align-items: center;
}
@media (max-width: 800px) { .ws-filters { grid-template-columns: 1fr; } }

.ws-status-section { margin-top: 1.5rem; }
.ws-status-section h3 { margin: 0 0 0.5rem; }

.ws-ticket-list, .ws-note-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.ws-ticket, .ws-note {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  box-shadow: var(--shadow);
}
.ws-ticket-head, .ws-note-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.ws-ticket-title, .ws-note-title { font-weight: 600; color: var(--text); }
.ws-ticket-meta, .ws-note-meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.3rem; font-size: 0.85rem; }

.ws-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg);
}
.ws-badge-kind.ws-kind-bug { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.ws-badge-kind.ws-kind-idea { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.ws-badge-kind.ws-kind-improvement { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.ws-badge-kind.ws-kind-task { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }

.ws-status-open { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.ws-status-in_progress { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.ws-status-done { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.ws-status-wontfix { background: var(--bg); color: var(--muted); }

.ws-prio {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.ws-prio-low { background: #9ca3af; }
.ws-prio-medium { background: #f59e0b; }
.ws-prio-high { background: #dc2626; }

.ws-tags { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; }
.ws-tag {
  font-size: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  color: var(--muted);
}

.ws-pin { color: #f59e0b; }

.ws-status-quick {
  margin-left: auto;
  font-size: 0.8rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  transition: background 0.3s ease;
}
.ws-status-quick.ws-status-saved { background: #d1fae5; }

.ws-ticket-detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.ws-ticket-detail-head h1 { margin: 0; font-size: 1.4rem; }

.ws-form { display: flex; flex-direction: column; gap: 0.75rem; }
.ws-form .form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
@media (max-width: 700px) { .ws-form .form-row { grid-template-columns: 1fr; } }

/* Markdown rendering (.prose) — readable defaults for tickets and notes. */
.prose { line-height: 1.6; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.3; margin: 1.4em 0 0.4em; }
.prose h1:first-child, .prose h2:first-child, .prose h3:first-child { margin-top: 0; }
.prose p { margin: 0.6em 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0.2em 0; }
.prose a { color: var(--accent); }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  font-size: 0.92em;
}
.prose pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75em 1em;
  overflow-x: auto;
}
.prose pre code { background: transparent; border: 0; padding: 0; }
.prose blockquote {
  border-left: 3px solid var(--border);
  margin: 0.6em 0;
  padding: 0.1em 0.9em;
  color: var(--muted);
}
.prose table { border-collapse: collapse; margin: 0.6em 0; }
.prose th, .prose td { border: 1px solid var(--border); padding: 0.35em 0.7em; }
.prose th { background: var(--bg); }
.prose img { max-width: 100%; height: auto; border-radius: 4px; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }

/* === Verlauf — CRM portfolio timeline === */

.verlauf-meta { padding: 0.5rem 1rem; }

.verlauf-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  padding: 0.5rem 1rem;
}
.verlauf-filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.verlauf-filter-channels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
  align-items: center;
  border: 0;
  padding: 0;
  margin: 0;
}
.verlauf-filter-channels legend {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0;
}
.verlauf-filter-channel {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.verlauf-filter-channel .verlauf-marker,
.verlauf-filter-channel .verlauf-marker:hover {
  position: static;
  transform: none;
}
.verlauf-filter-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.verlauf-section { padding: 0.75rem 1rem; }
.verlauf-section.is-archived { opacity: 0.7; }

.verlauf-summary {
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.25rem 0;
  list-style: none;
}
.verlauf-summary::-webkit-details-marker { display: none; }
.verlauf-summary::before {
  content: '▸';
  font-size: 0.8rem;
  color: var(--muted);
  transition: transform 0.15s ease;
  display: inline-block;
}
details[open] > .verlauf-summary::before {
  transform: rotate(90deg);
}
.verlauf-summary-name {
  font-weight: 600;
  color: var(--text);
  font-size: 1rem;
}

.verlauf-body { margin-top: 0.75rem; overflow-x: auto; }

.verlauf-grid-row {
  display: grid;
  grid-template-columns: 11rem 6.5rem 1fr;
  gap: 0.5rem;
  align-items: center;
  min-width: 600px;
}
.verlauf-grid-row[hidden],
.verlauf-section[hidden] { display: none; }

.verlauf-axis-row {
  height: 1.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.verlauf-axis {
  position: relative;
  height: 100%;
}
.verlauf-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-1px);
}
.verlauf-tick-line {
  width: 1px;
  height: 0.5rem;
  background: var(--border);
}
.verlauf-tick-label {
  margin-top: 0.05rem;
  font-variant-numeric: tabular-nums;
}

.verlauf-rows { display: flex; flex-direction: column; gap: 0.2rem; }
.verlauf-row {
  height: 1.9rem;
  border-radius: 4px;
  padding: 0 0.25rem;
  background: transparent;
}
.verlauf-row.crm-status-new { background: rgba(99, 102, 241, 0.06); }
.verlauf-row.crm-status-contacted { background: rgba(37, 99, 235, 0.06); }
.verlauf-row.crm-status-interested { background: rgba(16, 185, 129, 0.07); }
.verlauf-row.crm-status-not_interested { background: rgba(220, 38, 38, 0.05); }
.verlauf-row.crm-status-converted { background: rgba(245, 158, 11, 0.07); }
.verlauf-row.crm-status-dormant { background: rgba(107, 114, 128, 0.05); }

.verlauf-row-name {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.verlauf-row-name:hover { color: var(--accent); text-decoration: underline; }
.verlauf-row-status { font-size: 0.75rem; }

.verlauf-track {
  position: relative;
  height: 100%;
  border-left: 1px dashed var(--border);
}

.verlauf-today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #ef4444;
  pointer-events: none;
  z-index: 1;
}
.verlauf-axis-row .verlauf-today-line {
  background: #ef4444;
}

.verlauf-marker {
  position: absolute;
  top: 50%;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--ch-color, var(--muted));
  border: 1.5px solid var(--ch-color, var(--muted));
  z-index: 2;
  cursor: pointer;
  text-decoration: none !important;
}
.verlauf-marker:hover {
  transform: translate(-50%, -50%) scale(1.4);
  z-index: 3;
}
.verlauf-marker.is-inbound {
  background: var(--surface);
}
.verlauf-marker.ch-email   { --ch-color: #2563eb; }
.verlauf-marker.ch-call    { --ch-color: #10b981; }
.verlauf-marker.ch-demo    { --ch-color: #f59e0b; }
.verlauf-marker.ch-meeting { --ch-color: #8b5cf6; }
.verlauf-marker.ch-message { --ch-color: #06b6d4; }
.verlauf-marker.ch-note    { --ch-color: #9ca3af; }
.verlauf-marker.ch-other   { --ch-color: #6b7280; }

.verlauf-next {
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid #f59e0b;
  z-index: 2;
}
.verlauf-next.is-overdue {
  border-bottom-color: #ef4444;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.crm-timeline li.is-highlighted {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  transition: outline-color 0.5s ease;
}

/* Werkstatt ticket attachments */
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.85rem; }

.ws-attachments { margin-top: 1rem; }
.ws-attachments h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }

.ws-attachment-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  scroll-margin-top: 1rem;
}
.ws-attachment-row:first-of-type { border-top: none; padding-top: 0; }
.ws-attachment-row:target {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.ws-attachment-label { font-size: 0.95rem; }

.ws-attachment-preview { display: flex; }
.ws-attachment-thumb { display: inline-block; }
.ws-attachment-thumb img {
  max-height: 160px;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}
.ws-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
}
.ws-attachment-filename { font-weight: 500; }

.ws-attachment-caption-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.ws-attachment-caption-form .form-input { flex: 1 1 240px; min-width: 0; }

.ws-attachment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.ws-attachment-delete-form { display: inline; }

.ws-attachment-copymd-ok { background: #d1fae5; color: #065f46; }

.ws-attachment-upload {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}
.ws-attachment-upload .form-label { flex: 1 1 320px; }

/* Projekt detail page */
.projekt-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.projekt-header h1, .projekt-header h2 { margin: 0; }
.touchpoint-list { list-style: none; padding: 0; margin: 0; }
.touchpoint-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.touchpoint-list li:last-child { border-bottom: 0; }
.touchpoint-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.touchpoint-summary { margin-top: 0.25rem; font-size: 0.9rem; }

/* Rechner (cost calculator) */
.rechner-list { list-style: none; padding: 0; margin: 0; }
.rechner-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.rechner-list li:last-child { border-bottom: 0; }
.rechner-list-link { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem 0; }

.rechner-form { display: flex; flex-direction: column; gap: 1rem; }
.rechner-fieldset { border: 1px solid var(--border); padding: 1rem 1.25rem; margin: 0; }
.rechner-fieldset legend { padding: 0 0.5rem; font-weight: 600; color: var(--brand); }
.rechner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.rechner-field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0; }
.rechner-field-label { font-size: 0.9rem; color: var(--muted); }
.rechner-field-unit { font-style: italic; }
.rechner-field-hint { font-size: 0.75rem; line-height: 1.3; }

.rechner-results { background: var(--surface); }
.rechner-variants {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin: 0.5rem 0 1.5rem;
}
.rechner-variant {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--bg);
}
.rechner-variant--b { background: #eff6ff; border-color: #bfdbfe; }
.rechner-variant h4 { margin: 0 0 0.5rem; font-size: 1rem; }
.rechner-amount { display: flex; justify-content: space-between; padding: 0.25rem 0; }
.rechner-amount-label { color: var(--muted); font-size: 0.9rem; }
.rechner-amount-value { font-variant-numeric: tabular-nums; font-weight: 600; }

.rechner-breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 1rem;
  margin: 0;
}
.rechner-breakdown dt { color: var(--muted); font-size: 0.9rem; }
.rechner-breakdown dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; font-size: 0.9rem; }
.rechner-breakdown-sub { font-weight: 600; color: var(--text) !important; }
.rechner-breakdown-total {
  font-weight: 700;
  color: var(--text) !important;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

.rechner-role-table { display: flex; flex-direction: column; gap: 0.5rem; }
.rechner-role-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1.5fr;
  gap: 0.5rem;
  align-items: center;
}
.rechner-role-header {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0 0.25rem;
}
.rechner-role-header span { font-weight: 600; }
@media (max-width: 600px) {
  .rechner-role-row { grid-template-columns: 1fr; }
  .rechner-role-header { display: none; }
}
