/* ==========================================================================
   Clientela — Design nach verbindlichem caligatus-Branding
   Quelle: caligatus Pensum (Vault) + Live-Site caligatus.eu
   Helles Layout: Hellgrau-Fläche, weiße Karten, Navy-Text, Amber-Akzent.
   Navy-Verlauf nur im Header (Hero-Zone). Schrift: Inter.
   ========================================================================== */
:root {
  --navy-1:   #070e20;
  --navy-2:   #1a3264;
  --gradient: linear-gradient(140deg, #070e20 0%, #1a3264 100%);
  --amber:    #f59e0b;
  --amber-hover: #d98806;
  --white:    #ffffff;
  --lightgray:#f5f5f7;
  --muted:    #7a8399;
  --green:    #1f8a5b;
  --red:      #c0392b;

  --text:       #1a3264;
  --text-body:  #4a5470;
  --text-faint: #7a8399;
  --line:       rgba(26, 50, 100, 0.10);
  --line-soft:  rgba(26, 50, 100, 0.06);

  --shadow-card: 0 4px 16px rgba(26, 50, 100, .07);
  --shadow-lg:   0 20px 50px rgba(26, 50, 100, .18);

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--lightgray);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 30px;
  background: var(--gradient);
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 6px 24px rgba(7, 14, 32, .18);
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-name { font-weight: 800; font-size: 23px; letter-spacing: -.4px; color: var(--white); text-decoration: none; transition: opacity .15s ease; }
.brand-name:hover { opacity: .82; }
.brand-name .wm-g { color: var(--amber); }
.brand-sub {
  position: relative; color: rgba(255,255,255,.55); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 2.6px; cursor: help;
}
.brand-sub::after {
  content: attr(data-explain);
  position: absolute; top: 100%; left: 0; margin-top: 10px;
  width: max-content; max-width: 260px;
  background: var(--white); color: var(--text-body);
  font-size: 12.5px; font-weight: 400; text-transform: none; letter-spacing: normal; line-height: 1.5;
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .12s ease; z-index: 100;
}
.brand-sub:hover::after, .brand-sub:focus-visible::after { opacity: 1; visibility: visible; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sync-state { color: rgba(255,255,255,.72); font-size: 12.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-dot.ok { background: #46d68a; }
.sync-dot.busy { background: var(--amber); animation: pulse 1s infinite; }
.sync-dot.err { background: #ff6b6b; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; border-radius: 999px;
  padding: 9px 18px; cursor: pointer; color: var(--text);
  background: var(--white); transition: all .15s ease; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--amber); color: #241703; }
.btn-primary:hover { background: var(--amber-hover); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-body); }
.btn-ghost:hover { border-color: var(--amber); color: var(--text); }
.btn-danger { background: transparent; border-color: rgba(192,57,43,.4); color: var(--red); }
.btn-danger:hover { background: rgba(192,57,43,.08); }
/* Bestätigung einer unwiderruflichen Aktion — soll nicht wie eine gewöhnliche aussehen. */
.btn-danger-solid { background: var(--red); color: #fff; }
.btn-danger-solid:hover { background: #a33024; }
.btn-sm { padding: 6px 13px; font-size: 13px; }
.topbar .btn-ghost { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.22); color: rgba(255,255,255,.9); }
.topbar .btn-ghost:hover { border-color: var(--amber); color: var(--white); background: rgba(245,158,11,.16); }
.icon-btn { background: transparent; border: none; color: var(--text-faint); font-size: 18px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: var(--line-soft); }

/* ---------- Layout ---------- */
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 26px 30px 60px; flex: 1 0 auto; }
@media (max-width: 640px){ .wrap{ padding: 20px 16px 48px; } }

/* ---------- Connect / Onboarding ---------- */
.connect { max-width: 620px; margin: 8vh auto; text-align: center; }
.connect .card { background: var(--white); border-radius: var(--r-lg); box-shadow: var(--shadow-card); padding: 40px 36px; }
.connect h1 { font-size: 26px; margin: 0 0 8px; }
.connect p { color: var(--text-body); line-height: 1.6; margin: 0 0 20px; }
.connect .btn { font-size: 15px; padding: 12px 26px; }
.connect .sub-actions { margin-top: 16px; }
.connect .hint { font-size: 12.5px; color: var(--text-faint); margin-top: 22px; line-height: 1.6; }
.warn-box { background: #fff7e6; border: 1px solid rgba(245,158,11,.45); color: #7a5312; border-radius: var(--r-md); padding: 14px 16px; font-size: 13.5px; line-height: 1.55; margin-bottom: 22px; text-align: left; }
.warn-box strong { color: #b45309; }

/* ---------- Section head + toolbar ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .count { color: var(--text-faint); font-weight: 500; font-size: 14px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { position: relative; }
.search input {
  font-family: var(--font); font-size: 14px; color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px 9px 38px;
  background: var(--white); min-width: 240px; outline: none;
}
.search input:focus { border-color: var(--amber); }
.search::before { content: "⌕"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: 16px; }

/* ---------- Table (Firmenliste) ---------- */
.table-card { background: var(--white); border-radius: var(--r-lg); box-shadow: var(--shadow-card); overflow: hidden; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); font-weight: 600; padding: 14px 18px; border-bottom: 1px solid var(--line); }
table.grid td { padding: 13px 18px; border-bottom: 1px solid var(--line-soft); color: var(--text-body); }
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr { cursor: pointer; transition: background .12s ease; }
table.grid tbody tr:hover { background: #fafbfd; }
table.grid td.name { color: var(--text); font-weight: 600; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-faint); }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--line-soft); color: var(--text-body); }
.badge.lead { background: rgba(245,158,11,.15); color: #92600a; }
.badge.kunde { background: rgba(31,138,91,.14); color: #14603f; }
.badge.inaktiv { background: rgba(122,131,153,.16); color: #5b6376; }
/* Angebots-Phasen. Statusfarbe steht nie allein — der Text der Phase ist immer im Badge. */
.badge.offen { background: rgba(245,158,11,.15); color: #92600a; }
.badge.gewonnen { background: rgba(31,138,91,.14); color: #14603f; }
.badge.verloren { background: rgba(192,57,43,.13); color: #8f2b20; }
.sub-item .title .badge { margin-right: 8px; }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 9px; border-radius: 999px; background: rgba(26,50,100,.07); color: var(--text-body); margin: 0 4px 4px 0; }

/* ---------- Detail ---------- */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 6px; }
.detail-head h1 { font-size: 24px; margin: 0 0 4px; }
.detail-sub { color: var(--text-faint); font-size: 13.5px; }
.backlink { background: none; border: none; color: var(--text-faint); font-size: 13.5px; cursor: pointer; padding: 0; margin-bottom: 14px; }
.backlink:hover { color: var(--amber-hover); }
.panels { display: grid; grid-template-columns: 340px 1fr; gap: 22px; align-items: start; }
@media (max-width: 900px){ .panels { grid-template-columns: 1fr; } }
.panel { background: var(--white); border-radius: var(--r-lg); box-shadow: var(--shadow-card); padding: 22px 24px; }
.panel h2 { font-size: 15px; margin: 0 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.field-row:last-child { border-bottom: none; }
.field-row .k { color: var(--text-faint); flex: 0 0 118px; }
.field-row .v { color: var(--text-body); flex: 1; word-break: break-word; }
.sub-list { list-style: none; margin: 0; padding: 0; }
.sub-item { padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.sub-item:last-child { border-bottom: none; }
.sub-item .title { font-weight: 600; color: var(--text); }
.sub-item .meta { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.sub-item .body { font-size: 13.5px; color: var(--text-body); margin-top: 6px; line-height: 1.55; white-space: pre-wrap; }
/* Zeilen-Aktionen (Bearbeiten/Löschen) */
.sub-item .sub-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.head-actions { display: flex; gap: 8px; flex: none; flex-wrap: wrap; }
.hist-type { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--amber-hover); margin-right: 8px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(7,14,32,.5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 60; overflow-y: auto; }
.modal { background: var(--white); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; margin: 0; }
.modal-body { padding: 22px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
label.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-faint); font-weight: 500; }
label.fld input, label.fld select, label.fld textarea {
  font-family: var(--font); font-size: 14px; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 9px 11px; background: var(--white); outline: none;
}
label.fld input:focus, label.fld select:focus, label.fld textarea:focus { border-color: var(--amber); }
label.fld textarea { resize: vertical; min-height: 76px; }
/* Textfelder laufen als type="search" (gegen Chromes Adress-Autofill) — Such-Chrome ausblenden, damit sie wie normale Textfelder aussehen. */
label.fld input[type="search"] { -webkit-appearance: none; appearance: none; }
label.fld input[type="search"]::-webkit-search-decoration,
label.fld input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy-1); color: #fff; padding: 12px 20px; border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow-lg); z-index: 90; opacity: 0; transition: opacity .2s ease, transform .2s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---------- Footer ---------- */
.app-footer { flex: none; text-align: center; padding: 22px; color: var(--text-faint); font-size: 12.5px; }
.app-footer a { color: var(--text-faint); text-decoration: none; }
.app-footer a:hover { color: var(--amber-hover); }

/* ==========================================================================
   Auswertungen (Phase 2)
   Datenvisualisierung: eine Serie = eine Farbe (Navy), dünne Balken mit
   4px gerundetem Datenende, Werte direkt am Balkenende (nie nur im Tooltip),
   Beschriftungen in Ink-Farben — nie in der Datenfarbe.
   ========================================================================== */
.topnav { display: flex; gap: 4px; margin-right: 4px; }
.navlink {
  font-family: var(--font); font-size: 13.5px; font-weight: 600; cursor: pointer;
  background: none; border: 0; padding: 7px 12px; border-radius: 999px;
  color: rgba(255,255,255,.68);
}
.navlink:hover { color: #fff; background: rgba(255,255,255,.08); }
.navlink.active { color: var(--navy-1); background: #fff; }

.hero-panel { text-align: center; padding: 30px 24px 26px; margin-bottom: 18px; }
.hero-label { font-size: 13px; color: var(--text-faint); font-weight: 500; }
/* Hero-Zahl: gleiche Sans wie alles andere, proportionale Ziffern (kein tabular-nums). */
.hero-figure { font-size: 52px; line-height: 1.1; font-weight: 700; color: var(--text); margin: 6px 0 4px; letter-spacing: -0.02em; }
.hero-sub { font-size: 13px; color: var(--text-faint); }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
@media (max-width: 900px){ .stat-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px){ .stat-row { grid-template-columns: 1fr; } }
.stat { background: var(--white); border-radius: var(--r-md); box-shadow: var(--shadow-card); padding: 16px 18px; }
.stat .k { font-size: 12.5px; color: var(--text-faint); font-weight: 500; }
.stat .v { font-size: 24px; font-weight: 700; color: var(--text); margin: 4px 0 2px; letter-spacing: -0.01em; }
.stat .s { font-size: 12px; color: var(--text-faint); }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px){ .chart-grid { grid-template-columns: 1fr; } }
.panel.chart .empty { padding: 26px 12px; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label {
  flex: 0 0 132px; font-size: 12.5px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Spur: eine Stufe heller als die Fläche, haarfein — nie lauter als die Daten. */
.bar-track { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--line-soft); border-radius: 0 4px 4px 0; min-height: 14px; }
/* Balken: dünn (14px ≤ 24px), am Nullpunkt eckig, am Datenende 4px gerundet. */
.bar-fill { height: 14px; background: var(--navy-2); border-radius: 0 4px 4px 0; flex: 0 0 auto; min-width: 2px; }
.bar-value { font-size: 12.5px; font-weight: 600; color: var(--text-body); white-space: nowrap; }

.single-figure { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0 2px; }
.single-figure .k { font-size: 13px; color: var(--text-faint); }
.single-figure .v { font-size: 20px; font-weight: 700; color: var(--text); }

.panel-note { font-size: 12.5px; color: var(--text-faint); margin: -4px 0 10px; }

/* ==========================================================================
   Wiedervorlagen, Filter und Sortierung
   Fälligkeit trägt Farbe UND Text (Gruppentitel bzw. Datum) — nie Farbe allein.
   ========================================================================== */
.nav-count {
  display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 6px;
  border-radius: 999px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
}
.navlink.active .nav-count { background: var(--red); color: #fff; }

.wv-panel { margin-bottom: 16px; }
.wv-panel h2 { align-items: baseline; justify-content: flex-start; gap: 10px; }
.wv-head { font-size: 15px; }
.wv-head.ueberfaellig { color: var(--red); }
.wv-head.heute { color: #92600a; }
.wv-panel .count { color: var(--text-faint); font-weight: 500; font-size: 13px; }

.wv-list { list-style: none; margin: 0; padding: 0; }
.wv-item {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--line-soft); cursor: pointer;
}
.wv-item:last-child { border-bottom: none; }
.wv-item:hover { background: #fafbfd; }
.wv-date {
  flex: 0 0 104px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--text-body); padding-top: 1px;
}
.wv-date.ueberfaellig { color: var(--red); }
.wv-date.heute { color: #92600a; }
.wv-main { flex: 1; min-width: 0; }
.wv-firma { font-weight: 600; color: var(--text); }
.wv-schritt { font-size: 13.5px; color: var(--text-body); margin-top: 2px; line-height: 1.5; }
.wv-item .meta { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.wv-done { flex: none; }

/* Wiedervorlage-Marker in der Firmenliste */
.wv-tag {
  display: inline-block; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 2px 8px; border-radius: 999px; background: var(--line-soft); color: var(--text-body);
}
.wv-tag.ueberfaellig { background: rgba(192,57,43,.13); color: #8f2b20; }
.wv-tag.heute { background: rgba(245,158,11,.15); color: #92600a; }

/* Filter */
.filter {
  font-family: var(--font); font-size: 13.5px; color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px;
  background: var(--white); outline: none; max-width: 190px;
}
.filter:focus { border-color: var(--amber); }

/* Sortierbare Spaltenköpfe */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sortable.sorted { color: var(--text); }
th.sortable.sorted::after { content: " ▲"; font-size: 9px; }
th.sortable.sorted[data-dir="desc"]::after { content: " ▼"; }

/* Wiedervorlage: voller Kontext direkt in der Zeile */
.wv-ort { color: var(--text-faint); font-weight: 400; font-size: 13px; }
.wv-schritt { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.wv-todo {
  flex: none; font-size: 10.5px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: #92600a; background: rgba(245,158,11,.15); padding: 2px 7px; border-radius: 999px;
}
.wv-schritt.leer { color: var(--text-faint); font-style: italic; font-size: 13px; }
.wv-body {
  font-size: 13.5px; color: var(--text-body); line-height: 1.55; white-space: pre-wrap;
  margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--line);
}
.wv-wege { font-size: 12.5px; color: var(--text-faint); margin-top: 6px; }
.wv-link { color: var(--navy-2); text-decoration: none; border-bottom: 1px solid var(--line); }
.wv-link:hover { color: var(--amber-hover); border-bottom-color: var(--amber); }
.wv-body.clamped {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.wv-more {
  background: none; border: 0; padding: 2px 0; margin-top: 2px; cursor: pointer;
  font-family: var(--font); font-size: 12.5px; font-weight: 600; color: var(--navy-2);
}
.wv-more:hover { color: var(--amber-hover); }

/* Meldung mit Aktion (z. B. „Rückgängig") */
.toast { display: inline-flex; align-items: center; gap: 14px; }
.toast-action {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  color: var(--amber); text-decoration: underline; text-underline-offset: 3px;
  pointer-events: auto;
}
.toast-action:hover { color: #ffc45c; }
.toast.show { pointer-events: auto; }
/* Protokollvermerk einer eingelösten Wiedervorlage */
.erledigt-vermerk { color: var(--green); font-weight: 500; }

/* Angemeldetes Google-Konto — bei mehreren Konten die wichtigste Information */
.konto {
  color: rgba(255,255,255,.9); font-size: 12.5px; font-weight: 600;
  background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.20);
  padding: 4px 11px; border-radius: 999px;
  max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ==========================================================================
   Datenschutzerklärung (Fließtext-Dialog)
   Bewusst schmale Zeilenlänge und ruhiger Grauton — das ist Lesetext,
   keine Bedienoberfläche.
   ========================================================================== */
.modal-wide { max-width: 680px; }
.legal-text { max-height: 72vh; overflow-y: auto; }
.legal-text h3 {
  font-size: 14px; font-weight: 700; color: var(--text);
  margin: 22px 0 7px;
}
.legal-text h3:first-child { margin-top: 0; }
.legal-text p,
.legal-text li { font-size: 13.5px; line-height: 1.62; color: var(--text-body); margin: 0 0 10px; }
.legal-text ul { margin: 0 0 10px; padding-left: 20px; }
.legal-text li { margin-bottom: 7px; }
.legal-text code {
  font-size: 12.5px; background: var(--lightgray); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px;
}
.legal-text a { color: var(--navy-2); }
