/* ==========================================================================
   Media Hub — UI
   Helles, kartenbasiertes Layout: feste Seitenleiste mit Navigation, eine
   Kopfzeile mit Seitentitel und Verbindungsstatus, eine Karte pro Funktion.
   Farbwelt: warmes Papierweiss, Anthrazit, Waldgruen; Signet in Tinte.
   ========================================================================== */

:root {
  --bg: #f6f4ef;
  --bg-sidebar: #efebe3;
  --panel: #ffffff;
  --panel-raised: #faf8f4;
  --panel-hover: #f2efe8;
  --hairline: rgba(38, 36, 30, 0.09);
  --hairline-strong: rgba(38, 36, 30, 0.17);

  --text: #25272a;
  --muted: #5d6166;
  --muted-soft: #65696e;

  --accent: #3e6934;
  --accent-strong: #33592b;
  --accent-soft: rgba(63, 107, 53, 0.1);
  --accent-ink: #ffffff;
  --brand: #15171c;

  --green: #256d45;
  --green-soft: rgba(45, 132, 84, 0.11);
  --pink: #ad3549;
  --pink-soft: rgba(191, 58, 80, 0.09);
  --purple: #634bc1;
  --purple-soft: rgba(106, 83, 196, 0.1);
  --amber: #875a00;
  --amber-soft: rgba(214, 158, 20, 0.13);
  --blue: #2b66c1;
  --grey-soft: rgba(98, 102, 107, 0.1);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(38, 36, 30, 0.05), 0 6px 16px -10px rgba(38, 36, 30, 0.14);
  --shadow-md: 0 2px 6px rgba(38, 36, 30, 0.05), 0 22px 48px -22px rgba(38, 36, 30, 0.22);

  --sidebar-w: 248px;
  --font: "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-heading: "Montserrat", "Source Sans 3", system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* hidden gilt immer, auch fuer Elemente mit eigener display-Regel */
[hidden] { display: none !important; }

html { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  font-size: 16px;
}

::selection { background: var(--accent-soft); }

h1, h2, h3, h4, .stat-value { font-family: var(--font-heading); }

a { color: var(--accent); }

svg { display: block; }
svg use { pointer-events: none; }

/* Icons drawn from the sprite: outline style, inherit currentColor. */
.nav-icon,
.page-icon svg,
.tool-icon svg,
.option-icon svg,
.icon-btn svg,
.status-toggle .chev,
.menu-toggle svg,
.sidebar-close svg,
.bottom-item svg,
.search-trigger svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Login -------------------------------------------------------------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background:
    radial-gradient(60% 50% at 20% 10%, rgba(63, 107, 53, 0.10), transparent 60%),
    radial-gradient(50% 40% at 85% 90%, rgba(176, 140, 90, 0.10), transparent 60%),
    var(--bg);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2.5rem 2.25rem;
  text-align: center;
  width: min(100%, 24rem);
  box-shadow: var(--shadow-md);
}

.login-card .brand-mark.large {
  width: 56px;
  height: 56px;
  border-radius: 15px;
  margin: 0 auto var(--space-4);
}

.login-card h1 {
  margin: 0 0 var(--space-2) 0;
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
}

.login-card .hint { margin: 0 auto; }

.login-card #google-signin-button {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
}

.login-card .error-box { margin-top: var(--space-4); text-align: left; }

/* --- Shell: sidebar + main area ------------------------------------------ */

.shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  flex: none;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-3) var(--space-4);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0 var(--space-2) var(--space-5) var(--space-2);
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 11px;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 6px 14px -8px rgba(21, 23, 28, 0.55);
}

/* Signet: Knoten mit drei Verbindungen, siehe frontend/logo.svg */
.brand-mark svg { width: 100%; height: 100%; }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-family: var(--font-heading); font-weight: 600; font-size: 1.08rem; letter-spacing: 0; }
.brand-sub { font-size: 0.78rem; color: var(--muted); font-weight: 500; }

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-section {
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-soft);
  padding: var(--space-4) var(--space-3) var(--space-1);
}
.nav-section:first-child { padding-top: 0; }

.tab-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9rem;
  text-align: left;
  white-space: nowrap;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  position: relative;
}

.tab-btn:hover:not(:disabled) { background: var(--panel-raised); color: var(--text); }

.tab-btn.active {
  background: var(--panel-raised);
  border-color: var(--hairline);
  color: var(--text);
  font-weight: 600;
}

.tab-btn.active::before {
  content: "";
  position: absolute;
  left: -0.75rem;
  top: 30%;
  height: 40%;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

.tab-btn.active .nav-icon { color: var(--accent); }

.nav-icon {
  width: 18px;
  height: 18px;
  flex: none;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  min-width: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--panel-hover);
  border: 1px solid var(--hairline-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.81rem;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
}

.user-email {
  font-size: 0.84rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9rem;
  text-align: left;
  white-space: nowrap;
  background: transparent;
  color: var(--muted);
  border: none;
}

.sidebar-link:hover:not(:disabled) { background: var(--panel-raised); color: var(--text); }

/* --- Main area + topbar ---------------------------------------------------- */

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 244, 239, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--hairline);
}

.topbar-title { flex: 1; min-width: 0; }

.crumb {
  display: flex;
  gap: 0.4rem;
  font-size: 0.81rem;
  color: var(--muted-soft);
  font-weight: 500;
}
.crumb-sep { opacity: 0.6; }

.topbar h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* connection status dropdown */
.status-menu { position: relative; flex: none; }

.status-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--panel);
  border: 1px solid var(--hairline);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 0.45rem 0.8rem 0.45rem 0.7rem;
  font-size: 0.89rem;
  font-weight: 600;
}
.status-toggle:hover:not(:disabled) { background: var(--panel-raised); border-color: var(--hairline-strong); }
.status-toggle .chev { width: 14px; height: 14px; color: var(--muted); transition: transform 0.15s ease; }
.status-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted-soft);
  flex: none;
  box-shadow: 0 0 0 3px var(--grey-soft);
}
.status-dot.live { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.status-dot.warn { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.status-dot.error { background: var(--pink); box-shadow: 0 0 0 3px var(--pink-soft); }

.status-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(22rem, 90vw);
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-3);
  z-index: 60;
}

.status-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0 var(--space-1) var(--space-2);
}

.status-panel-foot {
  margin: var(--space-2) var(--space-1) 0;
  font-size: 0.8rem;
  color: var(--muted-soft);
}

.status-bar {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.89rem;
  font-weight: 500;
  color: var(--muted);
}
.pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-soft);
  flex: none;
}
.pill:hover { background: var(--panel-raised); }
.pill.live { color: var(--text); }
.pill.live::before { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.pill.error { color: var(--pink); }
.pill.error::before { background: var(--pink); box-shadow: 0 0 0 3px var(--pink-soft); }
.pill.not_configured { color: var(--muted-soft); }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover:not(:disabled) { background: var(--panel-raised); color: var(--text); }

/* --- Buttons / inputs ----------------------------------------------------- */

button {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

button:hover:not(:disabled) { background: var(--panel-hover); border-color: var(--hairline-strong); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
button.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: transparent; }

button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--hairline);
}
button.secondary:hover:not(:disabled) { color: var(--text); background: var(--panel-raised); }

input[type="number"],
input[type="text"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="password"],
textarea,
select {
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-family: var(--font);
  font-size: 0.9rem;
  color-scheme: light;
}

input[type="number"] { width: 6rem; }
input.wide { min-width: 18rem; flex: 1 1 18rem; }

input:focus,
select:focus,
textarea:focus { border-color: var(--accent); }

/* Fokus fuer Tastaturbedienung: 2px Vollfarbe mit Abstand (WCAG 2.4.11) */
:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  margin: 0;
}

pre {
  margin: 0;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.86rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

/* --- Page layout: head, tool cards, options ------------------------------- */

main { padding: var(--space-5) var(--space-6) var(--space-6); min-width: 0; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in 0.18s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page-icon {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-icon svg { width: 22px; height: 22px; }

.page-head h2 {
  margin: 0 0 0.2rem 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.page-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 62em;
}

.tool {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.tool-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}

.tool-icon {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool-icon svg { width: 18px; height: 18px; }
.tool-icon.meta { color: var(--purple); }

.tool-text { flex: 1; min-width: 0; }

.tool-text h3 {
  margin: 0.15rem 0 0.3rem 0;
  font-size: 1.02rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tool-text p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 68em;
}

.tool-meta {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
  max-width: 14rem;
}

.src-chip {
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.22rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  color: var(--muted);
  white-space: nowrap;
}
.src-chip.meta { color: var(--purple); border-color: rgba(106, 83, 196, 0.35); }

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-4);
}

.option {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.option:hover { border-color: var(--hairline-strong); background: var(--panel-hover); }

.option-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.2rem;
}
.option-icon svg { width: 16px; height: 16px; }

.option h4 { margin: 0; font-size: 0.94rem; font-weight: 650; }
.option p { margin: 0; color: var(--muted); font-size: 0.9rem; flex: 1; }
.option button { margin-top: var(--space-2); align-self: flex-start; background: var(--panel); }
.option button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--panel); }

.step {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.1rem;
}

.hint { color: var(--muted); font-size: 0.9rem; max-width: 60em; }

.summary-line {
  color: var(--text);
  font-size: 0.9rem;
  margin: 0 0 var(--space-3);
}
.summary-line:empty { display: none; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  align-items: center;
  margin: var(--space-4) 0;
}

.tool > .controls:last-child { margin-bottom: 0; }

.controls label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  padding: 0.3rem 0.4rem 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
}

.controls label.check { padding: 0.45rem 0.75rem; cursor: pointer; }

.controls label input[type="number"],
.controls label input[type="text"],
.controls label input[type="date"],
.controls label input[type="time"],
.controls label select {
  background: var(--panel);
  border-color: transparent;
  padding: 0.25rem 0.55rem;
}

.controls label input[type="number"] { width: 5.5rem; }

.controls.filters { padding-top: var(--space-3); border-top: 1px dashed var(--hairline); }

/* --- Tables / data panels -------------------------------------------------- */

.output { overflow-x: hidden; }
.output:empty { display: none; }
.output > p { margin: 0 0 var(--space-3); font-size: 0.9rem; }
.output > p.hint { margin-bottom: var(--space-3); }
.output > h3 { font-size: 1rem; margin: var(--space-5) 0 var(--space-3); }
.output > h4 { font-size: 0.89rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin: var(--space-4) 0 var(--space-2); }

.panel {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.tool .panel { background: var(--bg); }

.panel-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}

th, td {
  padding: 0.6rem 0.9rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--hairline);
}

th {
  background: var(--panel-raised);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

td { color: var(--text); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

tbody tr { transition: background-color 0.1s ease; }
tbody tr:hover { background: var(--panel-raised); }
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge.alert { background: var(--pink-soft); color: var(--pink); }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.tolerated { background: var(--amber-soft); color: var(--amber); }
.badge.pending { background: var(--grey-soft); color: var(--muted); }
.badge.meta { background: var(--purple-soft); color: var(--purple); }

.error-box {
  background: var(--pink-soft);
  border: 1px solid rgba(191, 58, 80, 0.28);
  color: #8f2436;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.86rem;
}

.empty-box {
  color: var(--muted);
  padding: var(--space-5) var(--space-4);
  text-align: center;
  font-size: 0.9rem;
  border: 1px dashed var(--hairline-strong);
  border-radius: var(--radius-md);
}

.panel > .empty-box { border: none; border-radius: 0; }

.loading {
  color: var(--muted);
  padding: var(--space-3) 0;
  display: flex;
  align-items: center;
  gap: 0.6em;
  font-size: 0.9rem;
}

.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--panel-hover);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Generic data table (filter + sort + paginate) ------------------------ */

.dt-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
}

.dt-quickfilter { min-width: 15rem; flex: 1 1 15rem; }

.dt-filter-row th {
  position: static;
  padding: 0.45rem 0.7rem;
  background: var(--panel);
  border-bottom: 1px solid var(--hairline);
}

.dt-filter-row input {
  width: 100%;
  font-size: 0.84rem;
  padding: 0.3rem 0.55rem;
  font-weight: 400;
}

.dt-filter-row .dt-range { display: flex; gap: 0.3rem; }
.dt-filter-row .dt-range input { width: 50%; min-width: 0; }

/* Sortier-Knopf: sieht aus wie die Kopfzeile, ist aber per Tastatur bedienbar */
.dt-sort-btn {
  display: inline-flex;
  align-items: center;
  padding: 0;
  margin: 0;
  min-height: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: inherit;
  cursor: pointer;
  user-select: none;
}
.dt-sort-btn:hover { background: none; color: var(--text); }
th.num .dt-sort-btn { justify-content: flex-end; }

.dt-sort-arrow { opacity: 0.35; margin-left: 0.35em; font-size: 0.7em; }
th.dt-sort-active .dt-sort-arrow { opacity: 1; color: var(--accent); }

.dt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--hairline);
  background: var(--panel);
  flex-wrap: wrap;
}

.dt-footer-count { color: var(--muted); font-size: 0.89rem; }
.dt-footer-actions { display: flex; gap: var(--space-2); }

/* --- Info icon + tooltip ---------------------------------------------------- */

.cell-with-info { display: inline-flex; align-items: center; }

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-left: 0.4em;
  border-radius: 50%;
  background: var(--grey-soft);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  font-style: normal;
  font-family: ui-monospace, monospace;
  line-height: 1;
  cursor: help;
  vertical-align: middle;
  flex: none;
  user-select: none;
}

.info-icon:hover,
.info-icon:focus-visible { background: var(--accent-soft); color: var(--accent); }

.info-tip-float {
  position: fixed;
  max-width: 290px;
  background: var(--panel-hover);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 400;
  line-height: 1.45;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline-strong);
  box-shadow: var(--shadow-md);
  z-index: 500;
  pointer-events: none;
  white-space: normal;
}

/* --- KPI dashboard --------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat-tile {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  position: relative;
}

.tool .stat-tile, .tool .chart-card, .tool .insight-item, .tool .campaign-card { background: var(--panel-raised); }

.stat-tile .stat-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.stat-tile .stat-value {
  font-size: clamp(1.15rem, 3.5vw, 1.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 0.35rem;
  overflow-wrap: break-word;
  font-variant-numeric: tabular-nums;
}

.stat-tile .stat-note { color: var(--muted-soft); font-size: 0.8rem; margin-top: 0.3rem; }

.chart-card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-4) var(--space-3);
  margin-bottom: var(--space-4);
}

.chart-card h3 { margin: 0 0 var(--space-3) 0 !important; font-size: 0.95rem !important; font-weight: 650; }

.viz-root {
  --chart-surface: var(--panel-raised);
  --chart-grid: rgba(38, 36, 30, 0.08);
  --chart-text: var(--muted);
}

.viz-root .chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viz-root .chart-area { stroke: none; }
.viz-root .chart-grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.viz-root .chart-axis-label { fill: var(--chart-text); font-size: 11px; font-family: var(--font); }
.viz-root .chart-hover-line { stroke: var(--muted); stroke-width: 1; opacity: 0; pointer-events: none; }
.viz-root .chart-hover-dot { opacity: 0; pointer-events: none; }
.viz-root .chart-hover-dot .dot-ring { fill: var(--panel-raised); }
.viz-root svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-root .chart-hit-area { fill: transparent; cursor: crosshair; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  box-shadow: var(--shadow-sm);
  transform: translate(-50%, -125%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 5;
}

.chart-tooltip .tt-period { opacity: 0.65; }
.chart-tooltip .tt-value { font-weight: 700; margin-left: 0.4em; }

.chart-wrap { position: relative; }

/* --- Campaign cards ---------------------------------------------------------- */

.campaign-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-3);
}

.campaign-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow: hidden;
  animation: card-in 0.35s ease backwards;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.campaign-card:hover { transform: translateY(-2px); border-color: var(--hairline-strong); }

.campaign-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.campaign-card.tone-good::before { background: var(--green); }
.campaign-card.tone-warn::before { background: var(--pink); }
.campaign-card.tone-neutral::before { background: var(--muted-soft); }

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.campaign-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.campaign-channel {
  font-size: 0.73rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-pill {
  font-size: 0.73rem;
  font-weight: 600;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.status-pill.enabled { background: var(--green-soft); color: var(--green); }
.status-pill.paused { background: var(--grey-soft); color: var(--muted); }

.campaign-card h4 {
  margin: 0 0 var(--space-3) 0;
  font-size: 0.92rem;
  font-weight: 650;
  line-height: 1.35;
  color: var(--text);
}

.campaign-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.campaign-metric {
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.55rem;
}

.campaign-metric .cm-label {
  display: block;
  font-size: 0.69rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.campaign-metric .cm-value {
  display: block;
  font-size: 0.92rem;
  font-weight: 650;
  margin-top: 0.15rem;
  overflow-wrap: break-word;
  font-variant-numeric: tabular-nums;
}

.campaign-tip {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.85rem;
  line-height: 1.4;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
}

.campaign-tip svg { flex: none; width: 15px; height: 15px; margin-top: 0.1rem; }
.campaign-tip.tone-good { background: var(--green-soft); color: var(--green); }
.campaign-tip.tone-warn { background: var(--pink-soft); color: var(--pink); }
.campaign-tip.tone-neutral { background: var(--grey-soft); color: var(--muted); }
.campaign-tip span { color: var(--text); }

.callout {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  background: var(--amber-soft);
  border: 1px solid rgba(214, 158, 20, 0.3);
  color: var(--amber);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  margin-bottom: var(--space-4);
}

.callout svg { flex: none; margin-top: 0.1rem; }
.callout p { margin: 0; color: var(--text); }
.callout .callout-label { color: var(--amber); font-weight: 650; display: block; margin-bottom: 0.15rem; }

.insight-list { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }

.insight-item {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  display: flex;
  gap: 0.65rem;
}

.insight-item .insight-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); flex: none; margin-top: 0.5em;
}

/* --- Mobile: hamburger + off-canvas sidebar drawer ------------------------- */

.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  padding: 0.45rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  flex: none;
}
.menu-toggle svg { width: 22px; height: 22px; }
.menu-toggle:hover:not(:disabled) { background: var(--panel-raised); }

.sidebar-close {
  display: none;
  margin-left: auto;
  background: transparent;
  border: none;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
}
.sidebar-close svg { width: 20px; height: 20px; }

.sidebar-backdrop { display: none; }

@media (max-width: 960px) {
  .tool-head { flex-wrap: wrap; }
  .tool-meta { order: 3; width: 100%; justify-content: flex-start; max-width: none; }
}

@media (max-width: 800px) {
  .menu-toggle { display: flex; align-items: center; justify-content: center; }

  .shell { position: relative; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 300px);
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(38, 36, 30, 0.35);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }

  main { padding: var(--space-4); }
  .topbar { padding: var(--space-3) var(--space-4); gap: var(--space-2); }
  .topbar h1 { font-size: 1.05rem; }
  .status-toggle #status-summary { display: none; }
  .status-toggle { padding: 0.45rem 0.6rem; }

  .tool { padding: var(--space-4); }
  .page-head { gap: var(--space-3); }
  .page-icon { width: 38px; height: 38px; }

  .controls label { width: 100%; justify-content: space-between; }
  .controls label.check { justify-content: flex-start; }
  input.wide { min-width: 0; width: 100%; }

  button, .sidebar-link, .tab-btn { min-height: 40px; }

  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }

}

/* --- Result cards (outcome of write actions: validate/create/send) --------- */

.result-card {
  position: relative;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-4) var(--space-3);
  overflow: hidden;
  animation: card-in 0.3s ease backwards;
}

.result-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 3px;
}
.result-card.tone-good::before { background: var(--green); }
.result-card.tone-warn::before { background: var(--amber); }
.result-card.tone-error::before { background: var(--pink); }

.result-head { display: flex; gap: var(--space-3); align-items: flex-start; }

.result-icon {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-icon svg { width: 18px; height: 18px; }
.tone-good .result-icon { background: var(--green-soft); color: var(--green); }
.tone-warn .result-icon { background: var(--amber-soft); color: var(--amber); }
.tone-error .result-icon { background: var(--pink-soft); color: var(--pink); }

.result-text { flex: 1; min-width: 0; }
.result-title { font-weight: 650; font-size: 0.98rem; line-height: 1.35; }
.result-detail { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; max-width: 64em; }

.result-rows {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem var(--space-4);
  margin: var(--space-3) 0 0 calc(34px + var(--space-3));
  font-size: 0.9rem;
}
.result-rows dt { color: var(--muted); margin: 0; }
.result-rows dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0 0 calc(34px + var(--space-3));
}

.result-link {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--hairline);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}
.result-link:hover { border-color: var(--accent); }

.result-tech {
  margin: var(--space-3) 0 0;
  border-top: 1px solid var(--hairline);
  padding-top: var(--space-2);
}
.result-tech summary {
  cursor: pointer;
  color: var(--muted-soft);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  user-select: none;
}
.result-tech summary:hover { color: var(--muted); }
.result-tech pre { margin-top: var(--space-2); background: var(--bg); font-size: 0.82rem; }

@media (max-width: 800px) {
  .result-rows, .result-actions { margin-left: 0; }
  .result-rows { grid-template-columns: 1fr; gap: 0.1rem; }
  .result-rows dt { margin-top: 0.4rem; font-size: 0.82rem; }
}

/* --- Small charts: donut / ring gauge / bar list / sparkline --------------- */

.chart-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.chart-row .chart-card { margin-bottom: 0; }

.chart-sub {
  margin: -0.35rem 0 var(--space-3) !important;
  color: var(--muted);
  font-size: 0.86rem;
}

/* donut */
.donut-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex-wrap: wrap;
}

.donut { width: 180px; height: 180px; flex: none; overflow: visible; }

.donut-slice {
  transition:
    stroke-dashoffset 0.9s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.15s ease,
    stroke-width 0.15s ease;
}
.donut-slice.is-dim { opacity: 0.3; }
.donut-slice.is-selected { stroke-width: 24; }

.donut-center-value {
  fill: var(--text);
  font-size: 21px;
  font-weight: 700;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.donut-center-label {
  fill: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  font-family: var(--font);
}

.donut-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 14rem;
  min-width: 0;
  max-width: 30rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.legend-item {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto 3.4em;
  align-items: center;
  gap: 0.7rem;
  padding: 0.32rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.89rem;
  transition: background-color 0.12s ease;
}
.legend-item.is-hot { background: var(--panel-hover); }
.legend-item.is-selected { background: var(--panel-hover); box-shadow: inset 0 0 0 1px var(--hairline-strong); }

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(38, 36, 30, 0.08);
}
.legend-swatch.is-marker {
  width: 2px;
  height: 12px;
  border-radius: 1px;
  background: var(--text);
  margin: 0 4px;
  box-shadow: none;
}

.legend-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.legend-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-note { color: var(--muted-soft); font-size: 0.78rem; }
.legend-value { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; text-align: right; }
.legend-share { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

.donut-wrap .chart-tooltip { transform: translate(-50%, -110%); }

/* ring gauge: ring on top, references listed underneath (never squeezed beside it) */
.gauge { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.gauge svg { width: 160px; height: 160px; overflow: visible; }
.gauge-arc { transition: stroke-dashoffset 1s cubic-bezier(0.22, 1, 0.36, 1); }
.gauge-marker { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.gauge-value { fill: var(--text); font-size: 22px; font-weight: 700; font-family: var(--font); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.gauge-label { fill: var(--muted); font-size: 10px; font-weight: 500; font-family: var(--font); }

.gauge-captions {
  list-style: none;
  margin: 0;
  padding: var(--space-2) 0 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.86rem;
  border-top: 1px solid var(--hairline);
}
.gauge-captions li { display: flex; align-items: center; gap: 0.55rem; }
.gauge-captions .legend-label { flex: 1; color: var(--muted); white-space: normal; }

/* horizontal bar list */
.bar-list { display: flex; flex-direction: column; gap: 0.5rem; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(6rem, 11rem) 1fr auto;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.89rem;
}
.bar-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 9px; border-radius: 5px; background: rgba(38, 36, 30, 0.07); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 5px; transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.bar-value { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* stat tile extras */
.stat-tile { display: flex; flex-direction: column; }
.stat-spark-wrap { margin-top: 0.55rem; }
.stat-spark { display: block; width: 100%; max-width: 160px; height: 30px; overflow: visible; }
.spark-line { transition: stroke-dashoffset 1.1s cubic-bezier(0.22, 1, 0.36, 1); }
.stat-delta { font-size: 0.8rem; font-weight: 600; margin-top: 0.35rem; }
.stat-delta.up { color: var(--green); }
.stat-delta.down { color: var(--pink); }

@media (max-width: 900px) {
  .chart-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .donut-slice, .gauge-arc, .bar-fill, .spark-line { transition: none; }
}

/* Sortimentsvergleich */

/* --- Rollen: Admin vs. Leser --------------------------------------------- */
[data-viewer] { display: none; }
body[data-role="viewer"] [data-admin] { display: none !important; }
body[data-role="viewer"] [data-admin-only],
body[data-role="editor"] [data-admin-only] { display: none !important; }
body[data-role="viewer"] [data-viewer] { display: block; }

.user-role { margin-left: auto; font-size: 0.69rem; }

/* --- Wochenreport ------------------------------------------------------------ */
.report-list { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.report-list:empty { display: none; }
.report-btn { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; padding: 0.5rem 0.9rem; }
.report-btn small { color: var(--muted); font-weight: 500; font-size: 0.78rem; }
.report-btn.active { border-color: var(--accent); color: var(--accent); }
.report-frame {
  width: 100%;
  height: 78vh;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: #fff;
}
.report-text { white-space: pre-wrap; font-family: var(--font); font-size: 0.9rem; color: var(--text); line-height: 1.55; }

/* PWA standalone: safe areas (Notch) beruecksichtigen */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(var(--space-4) + env(safe-area-inset-top)); }
  .sidebar { padding-top: calc(var(--space-5) + env(safe-area-inset-top)); }
  main { padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom)); }
}

/* Stat-Kacheln: Zahl skaliert mit der Kachelbreite, bricht nie um, wird nie abgeschnitten */
.stat-tile { container-type: inline-size; min-width: 0; }
.stat-tile .stat-value {
  white-space: nowrap;
  overflow: visible;
  font-size: clamp(1rem, 9cqw + 0.2rem, 1.6rem);
}
.stat-tile .stat-label, .stat-tile .stat-note, .stat-tile .stat-delta { overflow-wrap: anywhere; }

/* Zeile mit Hinweis (z. B. Seite antwortet nicht) */

/* Vorjahresvergleich in den Kennzahlen-Kacheln: klein, unten dran */
.stat-prior { margin-top: 0.45rem; padding-top: 0.4rem; border-top: 1px dashed color-mix(in srgb, var(--muted-soft) 45%, transparent); display: grid; gap: 0.15rem; }
.stat-prior-row { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: baseline; font-size: 0.76rem; line-height: 1.3; }
.stat-prior-label { color: var(--muted-soft); min-width: 5.2rem; }
.stat-prior-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.stat-prior-value.muted { color: var(--muted-soft); font-style: italic; }
.stat-prior-pct { font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-prior-pct.up { color: var(--green); }
.stat-prior-pct.down { color: var(--pink); }
.stat-prior-pct.neutral { color: var(--muted); }
.kpi-prior-note { margin: -0.4rem 0 1rem; font-size: 0.78rem; }

/* --- Kontakte: Firmen (CRM) und Zefix-Register -------------------------------- */

.tab-btn.not-connected { color: var(--muted-soft); }
.tab-btn.not-connected svg { opacity: 0.45; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.callout.stack { flex-direction: column; gap: 0.4rem; }
.callout.stack .steps { margin: 0; padding-left: 1.2rem; color: var(--text); }
.callout.stack .steps li { margin: 0.2rem 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0 0 var(--space-3); }
.chip-row .hint { margin-right: 0.2rem; }

.tag-chips { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; }
.tag-chip {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.tag-picker { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.35rem 0 var(--space-4); }
.tag-toggle {
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-pill);
  font-size: 0.86rem;
  font-weight: 500;
  background: var(--panel);
  color: var(--muted);
}
.tag-toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tag-toggle.on:hover:not(:disabled) { background: var(--accent-strong); color: var(--accent-ink); }
.tag-toggle.suggested { border-style: dashed; border-color: var(--accent); color: var(--accent); }

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.link-button:hover:not(:disabled) { background: none; text-decoration: underline; }

.button-link {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}
.button-link:hover { border-color: var(--accent); color: var(--accent); }

.due { color: var(--pink); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }

.back-button { margin-bottom: var(--space-4); }

.crm-head { padding-bottom: var(--space-4); }
.crm-title { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.crm-title h3 { margin: 0; font-family: var(--font-heading); font-size: 1.45rem; font-weight: 600; }
.crm-head .hint { margin: 0.3rem 0 var(--space-3); }
.crm-head .chip-row { margin: 0; }

.crm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); align-items: start; }
.crm-grid > .tool { margin: 0 !important; }
.crm-card h4 { margin: 0 0 var(--space-3); font-size: 1rem; font-weight: 650; }
.crm-card + .crm-card, .crm-grid + .crm-card { margin-top: var(--space-4); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin-bottom: var(--space-3); }

.form-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.form-field.wide { grid-column: 1 / -1; }
.form-field input, .form-field select, .form-field textarea { width: 100%; }
.form-label { font-size: 0.82rem; font-weight: 600; color: var(--muted); letter-spacing: 0.01em; }
textarea { resize: vertical; min-height: 5.5rem; line-height: 1.45; }
.form-actions { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-2); }
.check-line { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--muted); margin: var(--space-2) 0; }

.flash { font-size: 0.9rem; }
.flash.ok { color: var(--green); }
.flash.error { color: var(--pink); }

.crm-more { margin: 0 0 var(--space-3); border-top: 1px dashed var(--hairline); padding-top: var(--space-3); }
.crm-more summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-bottom: var(--space-3); }
.reg-info { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.9rem; }
.reg-info dt { color: var(--muted); font-weight: 600; }
.reg-info dd { margin: 0; }

.timeline { list-style: none; margin: var(--space-4) 0 0; padding: 0; border-top: 1px solid var(--hairline); }
.timeline-item { padding: var(--space-3) 0 var(--space-3) var(--space-4); border-bottom: 1px solid var(--hairline); position: relative; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1.05rem;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline-item.t-notiz::before { background: var(--muted-soft); }
.timeline-item.t-treffen::before { background: var(--blue); }
.timeline-item.t-email::before { background: var(--purple); }
.timeline-meta { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; align-items: baseline; font-size: 0.86rem; color: var(--muted); }
.timeline-meta strong { color: var(--text); font-size: 0.9rem; }
.timeline-item p { margin: 0.3rem 0 0; white-space: pre-wrap; font-size: 0.9rem; }
.timeline-empty { padding: var(--space-3) 0; color: var(--muted); font-size: 0.9rem; }

.icon-link {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted-soft);
  font-size: 1.05rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
}
.icon-link:hover:not(:disabled) { color: var(--pink); background: none; }

.crm-danger { margin: var(--space-5) 0 var(--space-2); text-align: right; }

.issue-block + .issue-block { margin-top: var(--space-5); }
.issue-block h4 { margin: 0; font-family: var(--font-heading); font-size: 1.1rem; font-weight: 600; }
.issue-block .hint { margin: 0.2rem 0 var(--space-3); }

.zefix-table td { vertical-align: top; }
.zefix-table td.zefix-firm { min-width: 16rem; }
.zefix-table td.zefix-firm > div { margin-top: 0.15rem; }
.zefix-table td.purpose { min-width: 18rem; line-height: 1.4; white-space: normal; }
.zefix-table td.zefix-firm { white-space: normal; }
.sub-title { margin: var(--space-5) 0 var(--space-3); font-size: 0.95rem; font-weight: 650; }

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

}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* Untere Leiste auf dem Handy (Schnellzugriff + «Mehr» fuer das Menue) */
.bottom-bar { display: none; }
@media (max-width: 800px) {
  .bottom-bar:not([hidden]) {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 0.2rem 0.25rem calc(0.2rem + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--hairline); box-shadow: 0 -2px 12px rgba(38, 36, 30, 0.06);
  }
  .bottom-item {
    flex: 1 1 0; min-width: 0; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.2rem; padding: 0.3rem 0.2rem; border: 0; border-radius: var(--radius-sm); background: none;
    color: var(--muted); font-size: 0.72rem; font-weight: 600;
  }
  .bottom-item:hover { background: var(--panel-raised); }
  .bottom-item svg { width: 22px; height: 22px; }
  .bottom-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-item.active { color: var(--accent); }
  .shell:has(.bottom-bar:not([hidden])) main { padding-bottom: calc(var(--space-4) + 64px + env(safe-area-inset-bottom)); }
  body:has(.bottom-bar:not([hidden])) .toast-region { bottom: calc(72px + env(safe-area-inset-bottom)); }
}

/* Tabellen als Karten auf dem Handy: jede Zeile eine Karte, jede Angabe mit
   ihrer Beschriftung (data-label). Titel ist die Hauptspalte (.cell-primary),
   Haekchen stehen davor, Knoepfe rechts. Sortieren und Filter als Leiste darueber. */
@media (max-width: 640px) {
  table.cards, table.cards > thead, table.cards > tbody, table.cards tr, table.cards td { display: block; }
  table.cards > thead > tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
    padding: 0.6rem 0.75rem; background: var(--panel-raised); border-bottom: 1px solid var(--hairline);
  }
  table.cards > thead th { display: block; padding: 0; border: 0; background: none; }
  table.cards > thead th:not(:has(input, button, select)) { display: none; }
  table.cards > thead > tr:not(:has(input, button, select)) { display: none; }
  table.cards > thead > tr.dt-head-row::before { content: "Sortieren"; margin-right: 0.15rem; color: var(--muted); font-size: 0.78rem; font-weight: 600; }
  table.cards .dt-sort-btn {
    min-height: 32px; padding: 0.25rem 0.65rem; border: 1px solid var(--hairline); border-radius: 999px;
    background: var(--panel); white-space: nowrap;
  }
  table.cards th.dt-sort-active .dt-sort-btn { border-color: var(--accent); color: var(--text); }
  table.cards > thead > tr.dt-filter-row th:has(input) { flex: 1 1 100%; }
  table.cards > thead > tr.dt-filter-row th:has(input)::before {
    content: attr(data-label); display: block; margin-bottom: 0.2rem; color: var(--muted); font-size: 0.78rem; font-weight: 600;
  }
  table.cards > tbody > tr {
    display: flex; flex-wrap: wrap; align-items: center; column-gap: 0.6rem; row-gap: 0.25rem;
    padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--hairline);
  }
  table.cards > tbody > tr:last-child { border-bottom: none; }
  table.cards > tbody td {
    display: flex; flex: 1 1 100%; justify-content: space-between; align-items: baseline; gap: 0.75rem;
    min-width: 0; padding: 0.1rem 0; border: 0; white-space: normal; text-align: right; overflow-wrap: anywhere;
  }
  table.cards > tbody td::before {
    content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); font-size: 0.8rem; text-align: left;
  }
  table.cards > tbody td[data-label=""] { flex: 0 0 auto; }
  table.cards > tbody td[data-label=""]::before,
  table.cards > tbody td.cell-primary::before { content: none; }
  table.cards > tbody td.cell-primary {
    display: block; flex: 1 1 0; order: -1; text-align: left; font-size: 1rem; font-weight: 600;
  }
  table.cards > tbody td[data-label=""]:has(~ td.cell-primary) { order: -2; }
  table.cards > tbody td.cell-primary ~ td[data-label=""] { margin-left: auto; }
  table.cards > tbody td:empty, table.cards > tbody td.cell-empty { display: none; }
  table.cards.zefix-table td { min-width: 0; }
}

/* --- Abos: Import und Formular ------------------------------------------------ */

.file-pick input[type="file"] { font-family: var(--font); font-size: 0.9rem; color: var(--text); min-width: 0; max-width: 100%; }
.file-pick input[type="file"]::file-selector-button {
  font-family: var(--font);
  font-weight: 600;
  margin-right: 0.75rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr)); gap: var(--space-2) var(--space-4); }
.map-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.1fr);
  gap: 0.6rem;
  align-items: center;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.map-row.unmapped { background: var(--panel-raised); }
.map-row.unmapped strong { color: var(--muted); }
.map-row select { width: 100%; }

.payer-card > summary { cursor: pointer; font-weight: 650; font-size: 0.95rem; margin-bottom: var(--space-3); }
.payer-card:not([open]) > summary { margin-bottom: 0; }
.crm-grid + .payer-card, .payer-card + .crm-card { margin-top: var(--space-4); }

/* Geplanter naechster Kontakt im Gespraechsverlauf */
.planned-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0.7rem 0.9rem;
  margin-bottom: var(--space-4);
  border: 1px solid var(--hairline-strong);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
}
.planned-box.is-due { border-left-color: var(--pink); background: var(--pink-soft); }
.planned-text { display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; align-items: baseline; font-size: 0.95rem; }
.planned-label { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.planned-box.is-due .planned-label { color: var(--pink); }
.planned-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.planned-actions input[type="text"] { width: 12rem; }
.timeline-closed { color: var(--green); font-size: 0.86rem !important; }

/* --- Media Hub: CRM, Kontaktsuche, Marketing, Integrationen --------------------- */

.tool-title { margin: 0 0 var(--space-3); font-size: 1.05rem; font-weight: 650; }

.search-grid {
  display: grid;
  grid-template-columns: 1.3fr 1.2fr 1fr 1fr 1.2fr;
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-2);
}
.search-grid select, .search-grid input { width: 100%; }
.search-grid select:disabled { opacity: 0.55; }

.import-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-3) 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-md);
  background: var(--accent-soft);
}
.import-bar .form-field { min-width: 13rem; }
.import-bar .check { display: inline-flex; align-items: center; gap: 0.45rem; padding-bottom: 0.45rem; font-size: 0.9rem; }

.bulk-bar {
  position: sticky;
  top: 4.6rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: 0.6rem 0.9rem;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--panel);
  box-shadow: var(--shadow-md);
}
.bulk-bar #crm-bulk-count { font-weight: 650; margin-right: auto; }
.bulk-bar .secondary { background: transparent; color: var(--panel); border-color: rgba(255, 255, 255, 0.35); }
.bulk-hint { text-align: right; margin: -0.4rem 0 0.4rem; font-size: 0.85rem; }

.name-cell { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.contact-cell { display: flex; flex-direction: column; gap: 0.1rem; }

.badge.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) {
  .badge.pulse { animation: none; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

.enrich-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: var(--panel-raised);
  border: 1px dashed var(--hairline-strong);
  font-size: 0.92rem;
}
.enrich-box.running { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.enrich-text { flex: 1 1 24rem; }
.enrich-sources { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.45rem; }
.src-chip.ok { color: var(--green); border-color: rgba(45, 132, 84, 0.35); background: var(--green-soft); text-decoration: none; }
.src-chip.off { color: var(--muted-soft); }
.button-link.social { font-size: 0.82rem; padding: 0.3rem 0.7rem; }

.crm-col { display: flex; flex-direction: column; gap: var(--space-4); }
.crm-col > .tool { margin: 0 !important; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.card-head h4 { margin: 0; }
.small-btn { padding: 0.3rem 0.75rem; font-size: 0.85rem; }

.contact-list { display: flex; flex-direction: column; gap: 0.5rem; }
.contact-row {
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.contact-row.primary { border-color: var(--accent); background: var(--accent-soft); }
.contact-row.editing { flex-direction: column; align-items: stretch; background: var(--panel-raised); }
.contact-main { flex: 1; min-width: 0; }
.contact-name { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.contact-reach { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin-top: 0.3rem; font-size: 0.9rem; }
.contact-reach a { color: var(--text); text-decoration: none; }
.contact-reach a:hover { color: var(--accent); }
.contact-sources { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.contact-sources .src-chip { font-size: 0.72rem; padding: 0.05rem 0.45rem; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 0.2rem; align-items: center; justify-content: flex-end; }
.icon-text {
  background: none;
  border: none;
  padding: 0.2rem 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.icon-text:hover:not(:disabled) { background: var(--panel-hover); color: var(--accent); }

.form-grid.six { grid-template-columns: 1.2fr 1fr 1.2fr 0.7fr 0.9fr 1.1fr; }

/* E-Mail-Dialog */
.mail-dialog {
  width: min(46rem, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  padding: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-md);
}
.mail-dialog::backdrop { background: rgba(38, 36, 30, 0.38); }
.dialog-body { padding: var(--space-5); }
.dialog-body h3 { margin: 0 0 var(--space-2); font-family: var(--font-heading); }
.mail-preview {
  margin: var(--space-3) 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
}
.mail-subject { font-weight: 650; margin: 0.35rem 0; }
.mail-body { white-space: pre-wrap; font-size: 0.92rem; line-height: 1.5; color: var(--text); }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr)); gap: var(--space-4); align-items: start; }
.template-grid > .tool { margin: 0; }
.template-grid > button { justify-self: start; }
.template-card .mail-body { color: var(--muted); max-height: 12rem; overflow: auto; border-radius: var(--radius-sm); }

/* Cockpit */
.pipeline { display: flex; gap: 3px; min-height: 2.6rem; border-radius: var(--radius-sm); overflow: hidden; }
.pipeline-seg {
  flex: 1 1 0;
  min-width: 5.5rem;
  border: none;
  border-radius: 0;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.pipeline-seg.st-neu { background: var(--grey-soft); }
.pipeline-seg.st-kontaktiert { background: var(--purple-soft); color: var(--purple); }
.pipeline-seg.st-interessiert { background: var(--amber-soft); color: var(--amber); }
.pipeline-seg.st-offerte { background: rgba(214, 158, 20, 0.24); color: var(--amber); }
.pipeline-seg.st-kunde { background: var(--green-soft); color: var(--green); }
.pipeline-seg.st-kein_interesse { background: var(--pink-soft); color: var(--pink); }
.pipeline-seg:hover:not(:disabled) { filter: brightness(0.96); }
.cockpit-row { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; align-items: baseline; padding: 0.45rem 0; border-bottom: 1px solid var(--hairline); }
.cockpit-row:last-child { border-bottom: none; }

/* Integrationen */
.integration-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); gap: var(--space-3); }
.integration { padding: var(--space-3) var(--space-4); border: 1px solid var(--hairline); border-radius: var(--radius-md); background: var(--panel); }
.integration.on { border-color: rgba(45, 132, 84, 0.35); }
.integration p { margin: 0.4rem 0; font-size: 0.9rem; }
.integration-head { display: flex; justify-content: space-between; gap: var(--space-2); align-items: flex-start; }
.code-example {
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-size: 0.82rem;
  overflow-x: auto;
  white-space: pre-wrap;
}

.enrich-progress { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: var(--space-4); }
.enrich-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

@media (max-width: 1100px) {
  .search-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .search-grid, .form-grid.six { grid-template-columns: 1fr; }
  .bulk-bar { top: 3.6rem; }
}

.tag-picker.collapsed .tag-toggle.extra { display: none; }
.tag-more { font-size: 0.85rem; padding: 0.25rem 0.3rem; }
#cockpit-output > .crm-grid { margin: var(--space-4) 0; }

/* Login mit E-Mail und Passwort */
.login-form { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-4); text-align: left; }
.login-form input { width: 100%; }
.login-form button { margin-top: var(--space-1); }
.login-divider { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-4) 0 0; color: var(--muted-soft); font-size: 0.85rem; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; border-top: 1px solid var(--hairline-strong); }
.login-card #login-setup code { font-size: 0.78rem; }

/* Bearbeiter sehen keine Admin-Einstellungen */
body[data-role="editor"] #tab-settings [data-admin] { display: none !important; }

/* --- Auf- und zuklappbare Bereiche ------------------------------------------- */
.collapsible > .collapse-head { cursor: pointer; position: relative; }
.collapsible > .collapse-head:hover h3, .collapsible > .collapse-head:hover h4, .collapsible > .collapse-head:hover { color: var(--accent-strong); }
.tool-head.collapse-head { align-items: center; }
h3.collapse-head, h4.collapse-head, .crm-title.collapse-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding-right: 2.6rem; }
.collapse-toggle {
  flex: none;
  margin-left: auto;
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--muted);
}
h3.collapse-head > .collapse-toggle, h4.collapse-head > .collapse-toggle, .crm-title.collapse-head > .collapse-toggle {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
}
.collapse-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.18s ease; transform: rotate(180deg); }
.collapsible.collapsed .collapse-toggle svg { transform: rotate(0deg); }
.collapse-toggle:hover:not(:disabled) { background: var(--panel-hover); color: var(--accent); }

.collapsible.collapsed > :not(.collapse-head) { display: none !important; }
.collapsible.collapsed { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.collapsible.collapsed .tool-text p, .collapsible.collapsed .tool-meta { display: none; }
.collapsible.collapsed .tool-head { margin-bottom: 0; }
.collapsible.collapsed h4.collapse-head, .collapsible.collapsed h3.collapse-head, .collapsible.collapsed .crm-title.collapse-head { margin-bottom: 0; }

.tool-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--grey-soft);
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  vertical-align: middle;
}
.tool-badge.alert { background: var(--pink-soft); color: var(--pink); }
.tool-badge.ok { background: var(--green-soft); color: var(--green); }
.tool-badge[hidden] { display: none; }

/* --- Mandanten: Organisation wechseln, Integrationen, Plattform ------------- */
.tenant-switch { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: var(--space-3); }
.tenant-switch select { width: 100%; }
.mail-dialog.narrow { width: min(32rem, calc(100vw - 2rem)); }
button.small { padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.icon-text.danger { color: var(--pink); }
.icon-text.danger:hover:not(:disabled) { color: var(--pink); background: var(--pink-soft); }
.integration { display: flex; flex-direction: column; }
.integration-foot { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; margin-top: auto; padding-top: var(--space-2); }
.integration-actions { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.error-text { color: var(--pink); }
.summary-line.ok-line { color: var(--green); background: var(--green-soft); border-radius: var(--radius-sm); padding: 0.55rem 0.8rem; }
.secret-notice { margin: 0 0 var(--space-4); }
.secret-notice p { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88rem; word-break: break-all; }
.secret-notice button { align-self: flex-start; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.4rem 1rem; margin-bottom: var(--space-3); }
.check-row { display: flex; gap: 0.5rem; align-items: center; cursor: pointer; }
.check-row input { width: auto; margin: 0; }
.chip-x { border: none; background: none; padding: 0 0.15rem; margin-left: 0.1rem; color: var(--muted); font-size: 0.95rem; line-height: 1; cursor: pointer; }
.chip-x:hover { color: var(--pink); }
/* Gedaempfte Zeile (gesperrt, schon im CRM): andere Flaeche statt Deckkraft,
   damit der Text lesbar bleibt (Kontrast) */
tr.row-muted td { background: var(--bg); color: var(--muted); }
.status-select.st-aktiv { color: var(--green); }
.status-select.st-test { color: var(--amber); }
.status-select.st-gesperrt { color: var(--pink); }
#tab-platform td input, #tab-platform td select { min-width: 8rem; }
#tab-platform .chip-row { margin: 0; }
.login-note { margin-top: var(--space-3); text-align: center; }
/* Nur Admins aendern Integrationen und Profil; Bearbeiter und Leser sehen sie */
body[data-role="editor"] #tab-organisation [data-admin],
body[data-role="viewer"] #tab-organisation [data-admin] { display: none !important; }

/* --- Rueckfragen und Hinweise ------------------------------------------------ */
button.secondary.danger { color: var(--pink); }
button.secondary.danger:hover:not(:disabled) { color: var(--pink); background: var(--pink-soft); border-color: var(--pink); }
button.primary.danger { background: var(--pink); border-color: var(--pink); }
button.primary.danger:hover:not(:disabled) { background: #a32f44; border-color: #a32f44; }
.confirm-dialog .dialog-body p { margin: 0 0 var(--space-4); line-height: 1.5; }
.toast-region {
  position: fixed; left: 50%; bottom: calc(var(--space-5) + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--space-2); z-index: 200; width: min(32rem, calc(100vw - 2rem));
}
.toast {
  display: flex; align-items: center; gap: var(--space-3); padding: 0.7rem 0.9rem;
  border-radius: var(--radius-md); background: #25272a; color: #fff; box-shadow: var(--shadow-md); font-size: 0.92rem;
}
.toast.error { background: #8f2236; }
.toast span { flex: 1; }
.toast-action { background: none; border: 1px solid rgba(255,255,255,0.5); color: #fff; padding: 0.25rem 0.6rem; border-radius: var(--radius-sm); }
.toast-close { background: none; border: none; color: #fff; font-size: 1.2rem; line-height: 1; padding: 0 0.2rem; cursor: pointer; }

/* --- Oeffentliche Seiten ohne Anmeldung (Abmelden per Link) ------------------ */
.public-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: var(--space-4); }
.public-card {
  width: min(32rem, 100%); padding: var(--space-5); border: 1px solid var(--hairline);
  border-radius: var(--radius-md); background: var(--panel); box-shadow: var(--shadow-md);
}
.public-card h1 { margin: 0 0 var(--space-3); font-size: 1.3rem; }
.public-card p { line-height: 1.55; }
.public-card form { margin-top: var(--space-4); }

/* --- Aufgaben ----------------------------------------------------------------- */
.task-add { display: grid; grid-template-columns: 2.4fr 1fr 0.8fr 1.2fr 0.9fr auto; gap: var(--space-3); align-items: end; }
.task-add .form-field.wide { grid-column: auto; }
.task-add.compact { grid-template-columns: 1fr auto auto; margin-top: var(--space-3); }
.chip-toggle {
  min-height: 32px; padding: 0.3rem 0.85rem; border: 1px solid var(--hairline); border-radius: 999px;
  background: var(--panel); color: var(--muted); font-weight: 600; font-size: 0.85rem;
}
.chip-toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.task-group { margin-bottom: var(--space-4); }
.task-group h3 { margin: 0 0 var(--space-2); font-size: 0.95rem; color: var(--muted); }
.task-group.group-ueberfaellig h3 { color: var(--pink); }
.task-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--hairline); border-radius: var(--radius-md); background: var(--panel); }
.crm-card .task-list:empty { display: none; }
.task-item { display: flex; align-items: flex-start; gap: var(--space-3); padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--hairline); }
.task-item:last-child { border-bottom: none; }
.task-item.prio-hoch { box-shadow: inset 3px 0 0 var(--pink); }
.task-item input[type="checkbox"] { margin-top: 0.2rem; width: 1.15rem; height: 1.15rem; flex: none; }
.task-main { flex: 1 1 auto; min-width: 0; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-top: 0.15rem; color: var(--muted); font-size: 0.85rem; }
@media (max-width: 800px) {
  .task-add { grid-template-columns: 1fr 1fr; }
  .task-add .form-field.wide, .task-add button { grid-column: 1 / -1; }
  .task-add.compact { grid-template-columns: 1fr auto; }
  .task-add.compact input[type="text"] { grid-column: 1 / -1; }
}

/* --- Suche ueber alles (Cmd+K) ---------------------------------------------- */

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--hairline);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 0.45rem 0.6rem 0.45rem 0.75rem;
  font-size: 0.89rem;
  font-weight: 600;
}
.search-trigger:hover:not(:disabled) { background: var(--panel-raised); border-color: var(--hairline-strong); color: var(--text); }
.search-trigger svg { width: 16px; height: 16px; }
.search-trigger-key {
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted-soft);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  padding: 0 0.35rem;
  line-height: 1.5;
}

.palette {
  width: min(40rem, calc(100vw - 2rem));
  max-height: min(34rem, calc(100vh - 6rem));
  margin: 12vh auto auto;
  padding: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.palette[open] { display: flex; flex-direction: column; }
.palette::backdrop { background: rgba(38, 36, 30, 0.38); }
.palette-head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--hairline); }
.palette-input { flex: 1; min-width: 0; font-size: 1.05rem; }
.palette-close { font-size: 0.78rem; padding: 0.2rem 0.5rem; border-radius: 6px; background: var(--panel-raised); border: 1px solid var(--hairline-strong); color: var(--muted); }
.palette-list { overflow-y: auto; padding: var(--space-2) 0; }
.palette-list:empty { display: none; }
.palette-group + .palette-group { margin-top: var(--space-2); }
.palette-group-title { padding: 0.3rem var(--space-4); font-size: 0.78rem; font-weight: 650; color: var(--muted-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.palette-option { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.5rem var(--space-4); cursor: pointer; }
.palette-option[aria-selected="true"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.palette-title { font-weight: 600; }
.palette-sub { font-size: 0.86rem; color: var(--muted); }
.palette-status { margin: 0; padding: 0.55rem var(--space-4); font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--hairline); }

@media (max-width: 800px) {
  .search-trigger { padding: 0.5rem; }
  .search-trigger-label, .search-trigger-key { display: none; }
  .palette { width: calc(100vw - 1rem); max-width: none; margin-top: 0.5rem; max-height: calc(100dvh - 1rem); }
}

/* --- Papierkorb ---------------------------------------------------------------- */
.trash-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.trash-item { display: flex; gap: var(--space-3); align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: var(--space-3); border: 1px solid var(--hairline); border-radius: var(--radius-sm); background: var(--panel-raised); }
.trash-text { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; flex: 1 1 16rem; }
.trash-title { font-weight: 600; overflow-wrap: anywhere; }
.trash-sub { font-size: 0.86rem; color: var(--muted); }
.trash-actions { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; }
