/*
 * CRM – Stil (Design nach Topseal ERP v2, „Petrol-Redesign")
 *
 * Grundidee: warmes Light-Theme — Petrol #0f6a5e auf Off-White #f7f6f3,
 * weiße Karten mit 1px-Rahmen #e6e4df und 12px-Radius statt Schatten,
 * Schrift Inter 14px. Beim Einbau in ein Projekt nur die Variablen anpassen.
 * Basis identisch zum Belegsystem-Modul, unten ergänzt um CRM-Bausteine
 * (Historie-Zeitleiste, Kontakt-Karten).
 */

:root {
  --primary: #0f6a5e;        /* Petrol: Buttons, Links, aktive Zustände */
  --primary-hell: #2f8b7d;   /* Fokus-Ring */
  --primary-dunkel: #0b544b; /* Button-Hover, aktive Nav-Links */
  --primary-10: rgba(15, 106, 94, .10);
  --primary-5: rgba(15, 106, 94, .05);
  --rot: #dc2626;
  --ink: #111827;            /* Haupttext */
  --grau-700: #374151;       /* Labels, Tabellenköpfe */
  --grau-600: #4b5563;
  --grau-500: #6b7280;
  --muted: #6b7280;          /* Sekundärtext */
  --grau-400: #9ca3af;       /* Gruppentitel, Icons, Platzhalter */
  --grau-300: #d1d5db;
  --border: #e6e4df;         /* ALLE Rahmen und Trennlinien (warmes Graubeige) */
  --app: #f7f6f3;            /* Seitenhintergrund (warmes Off-White) */
  --flaeche: #f9fafb;        /* Tabellenkopf, Fußleisten */
  --flaeche-2: #f3f4f6;      /* Segmented-Control-Hintergrund, Hover */
  --radius: 12px;            /* Karten */
  --radius-klein: 8px;       /* Buttons, Inputs */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--app);
  color: var(--ink);
  font: 400 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
h1 { font-size: 24px; font-weight: 700; color: var(--ink); margin: 0; }
h2 { font-size: 16px; font-weight: 600; color: var(--ink); margin: 0; }

/* ─── Grundgerüst: Sidebar links, Kopfleiste, Inhalt ────────────────────── */

.seitenleiste {
  position: fixed; left: 0; top: 0; bottom: 0; width: 240px;
  background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 20;
}
.seitenleiste .logo {
  height: 56px; display: flex; align-items: center; padding: 0 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 15px; color: var(--ink); gap: 8px;
}
.seitenleiste .logo .punkt {
  width: 10px; height: 10px; border-radius: 3px; background: var(--primary);
  flex: 0 0 auto;
}
.seitenleiste nav { flex: 1; padding: 12px; overflow-y: auto; }
.seitenleiste .gruppe {
  padding: 0 12px 6px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--grau-400);
}
.seitenleiste .gruppe:not(:first-child) {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
}
.seitenleiste nav a {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  border-radius: var(--radius-klein); font-size: 14px; text-decoration: none;
  color: var(--grau-600); transition: background .15s, color .15s;
}
.seitenleiste nav a:hover { background: var(--flaeche-2); color: var(--ink); }
.seitenleiste nav a.aktiv { background: var(--primary-10); color: var(--primary-dunkel); font-weight: 500; }
.seitenleiste nav a svg { width: 16px; height: 16px; flex: 0 0 auto; }
.seitenleiste .fuss {
  padding: 12px 20px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--grau-400);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.hauptbereich { margin-left: 240px; min-height: 100vh; }
.kopfleiste {
  height: 56px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding: 0 24px; font-size: 13px; color: var(--muted);
}
.kopfleiste .kw {
  background: var(--flaeche-2); border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 600; color: var(--grau-600);
}
.kopfleiste .strich { width: 1px; height: 20px; background: var(--border); }
.kopfleiste a { color: var(--grau-600); text-decoration: none; font-size: 13px; }
.kopfleiste a:hover { color: var(--ink); text-decoration: underline; }
main { padding: 24px; display: flex; flex-direction: column; gap: 16px; }

/* ─── Karten ────────────────────────────────────────────────────────────── */

.karte {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.karte.ohne-innenabstand { padding: 0; overflow: hidden; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-klein); font: 500 14px var(--font);
  padding: 8px 16px; cursor: pointer; text-decoration: none;
  transition: background .15s, color .15s; border: 1px solid transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dunkel); }
.btn-outline { background: #fff; color: var(--grau-700); border-color: var(--border); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.btn-outline:hover:not(:disabled) { background: var(--flaeche); }
.btn-rot { background: var(--rot); color: #fff; }
.btn-rot:hover:not(:disabled) { background: #b91c1c; }
.btn-klein { padding: 6px 12px; font-size: 14px; }
.textlink-rot {
  background: none; border: none; padding: 0; cursor: pointer;
  font: 400 12px var(--font); color: var(--rot);
}
.textlink-rot:hover { text-decoration: underline; }

/* ─── Status-Badges ─────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 4px 8px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.neu, .badge.teilbezahlt { background: #fef3c7; color: #b45309; } /* Amber */
.badge.offen { background: #d9ece8; color: #0b544b; }                   /* Petrol hell */
.badge.faellig, .badge.gemahnt { background: #fee2e2; color: #b91c1c; } /* Rot */
.badge.bezahlt { background: #dcfce7; color: #15803d; }                 /* Grün */
.badge.grau, .badge.storniert { background: #f3f4f6; color: #4b5563; }

/* ─── Status-Tabs (Segmented Control mit Summen) ────────────────────────── */

.tabs {
  display: flex; gap: 4px; background: var(--flaeche-2);
  border-radius: var(--radius-klein); padding: 4px; flex-wrap: wrap;
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; line-height: 1.2;
  padding: 4px 12px; border-radius: 6px; font-size: 14px;
  color: var(--grau-500); text-decoration: none;
}
.tabs a small { font-size: 10px; }
.tabs a:hover { color: var(--grau-700); }
.tabs a.aktiv {
  background: #fff; color: var(--ink); font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

/* ─── Formulare ─────────────────────────────────────────────────────────── */

.feld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.feld label { font-size: 14px; font-weight: 500; color: var(--grau-700); }
input[type="text"], input[type="search"], input[type="date"],
input[type="password"], input[type="email"], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-klein);
  padding: 8px 12px; font: 400 14px var(--font); color: var(--ink);
  background: #fff;
}
input::placeholder { color: var(--grau-400); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: transparent;
  box-shadow: 0 0 0 2px var(--primary-hell);
}
textarea { min-height: 60px; resize: vertical; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }

/* ─── Tabellen ──────────────────────────────────────────────────────────── */

.tabelle { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabelle thead th {
  background: var(--flaeche); border-bottom: 1px solid var(--border);
  padding: 12px; text-align: left; font-weight: 500; color: var(--grau-700);
  position: sticky; top: 0; z-index: 5;
}
.tabelle tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.tabelle tbody tr:last-child td { border-bottom: none; }
.tabelle tbody tr.klickbar { cursor: pointer; }
.tabelle tbody tr.klickbar:hover { background: var(--flaeche); }
.tabelle tbody tr.ausgewaehlt { background: var(--primary-5); }
.tabelle tbody tr.gedimmt { opacity: .5; }
.tabelle .betrag { text-align: right; white-space: nowrap; font-family: var(--mono); }
.scrollbereich { max-height: calc(100vh - 330px); overflow-y: auto; }
.tabellenfuss {
  padding: 10px 16px; border-top: 1px solid var(--border); background: var(--flaeche);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; font-size: 13px; color: var(--muted);
}

/* ─── Detail-Raster (Label über Wert) ───────────────────────────────────── */

.detail-raster {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 14px;
}
.detail-raster > div { display: flex; flex-direction: column; gap: 2px; }
.detail-raster span.label { font-size: 12px; color: var(--muted); }

/* ─── Drag-&-Drop-Zone ──────────────────────────────────────────────────── */

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--flaeche); padding: 32px 16px; text-align: center;
  cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  align-items: center; transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: #2dd4bf; background: rgba(240, 253, 250, .5); }
.dropzone.aktiv { border-color: #14b8a6; background: #f0fdfa; }
.dropzone.laedt { border-color: #5eead4; background: #f0fdfa; cursor: wait; }
.dropzone .titel { font-size: 14px; font-weight: 500; color: var(--grau-700); }
.dropzone .untertitel { font-size: 12px; color: var(--muted); }

/* ─── Modal ─────────────────────────────────────────────────────────────── */

.modal-hintergrund {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 50;
  display: none; align-items: flex-start; justify-content: center; padding: 48px 16px;
}
.modal-hintergrund.offen { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 640px; max-width: 100%;
  max-height: 85vh; overflow-y: auto; padding: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25);
  display: flex; flex-direction: column; gap: 14px;
}
.modal .kopf { display: flex; justify-content: space-between; align-items: center; }
.modal .schliessen {
  width: 32px; height: 32px; border-radius: var(--radius-klein); border: none;
  background: var(--flaeche-2); color: var(--grau-500); cursor: pointer;
  font-size: 15px; line-height: 1;
}
.modal .schliessen:hover { background: #e5e7eb; }

/* ─── Aufklapp-Menü (details-Element) ───────────────────────────────────── */

details.menue { position: relative; }
details.menue summary {
  list-style: none; cursor: pointer; user-select: none;
}
details.menue summary::-webkit-details-marker { display: none; }
details.menue .menue-inhalt {
  position: absolute; right: 0; top: calc(100% + 6px); width: 288px; z-index: 30;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  animation: menue-auf .14s ease-out;
}
details.menue .menue-inhalt.links { right: auto; left: 0; }
@keyframes menue-auf {
  from { opacity: 0; transform: scale(.96) translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* ─── Hinweis- und Flash-Boxen ──────────────────────────────────────────── */

.hinweis {
  border-radius: var(--radius-klein); border: 1px solid; padding: 10px 14px;
  font-size: 14px;
}
.hinweis.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.hinweis.fehler { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.hinweis.warnung { background: #fffbeb; border-color: #fcd34d; color: #92400e; }
.hinweis.info { background: #f0fdfa; border-color: #99f6e4; color: #0f766e; }

/* ─── Kategorie-Kacheln (Ausgabenübersicht) ─────────────────────────────── */

.kachel-raster {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.kachel {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 4px;
  text-decoration: none; transition: border-color .15s, background .15s;
}
.kachel:hover { border-color: var(--primary-hell); }
.kachel.aktiv { border-color: var(--primary); background: var(--primary-5); }
.kachel .betrag { font-size: 18px; font-weight: 600; color: var(--ink); }
.kachel .name { font-size: 14px; font-weight: 500; color: var(--grau-700); }
.kachel .anzahl { font-size: 12px; color: var(--muted); }

/* ─── Zweispalten-Arbeitsplatz der Belegseite ───────────────────────────── */

.beleg-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1200px) { .beleg-layout { grid-template-columns: 1fr; } }

.vorschau-rahmen {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-klein);
  background: var(--flaeche-2);
}

/* ─── Login-Seite (Standalone-App) ──────────────────────────────────────── */

.login-mitte {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--app);
}
.login-karte {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; width: 360px; max-width: 100%;
  display: flex; flex-direction: column; gap: 16px;
}

/* ─── Kleinkram ─────────────────────────────────────────────────────────── */

.muted { color: var(--muted); }
.klein { font-size: 12px; }
.mono { font-family: var(--mono); }
.zeile { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.zeile.auseinander { justify-content: space-between; }
.spalte { display: flex; flex-direction: column; gap: 16px; align-self: start; }

@media print {
  .seitenleiste, .kopfleiste { display: none; }
  .hauptbereich { margin-left: 0; }
  main { padding: 0; }
}

/* ─── CRM-Bausteine ─────────────────────────────────────────────────────── */

/* Historie als Zeitleiste: Punkt + Linie links, Eintrag rechts */
.zeitleiste { display: flex; flex-direction: column; }
.zeitleiste .eintrag {
  position: relative; padding: 0 0 16px 22px;
}
.zeitleiste .eintrag::before {          /* Punkt */
  content: ""; position: absolute; left: 0; top: 5px;
  width: 9px; height: 9px; border-radius: 999px;
  background: var(--primary); border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
}
.zeitleiste .eintrag::after {           /* Linie nach unten */
  content: ""; position: absolute; left: 4px; top: 18px; bottom: 0;
  width: 1px; background: var(--border);
}
.zeitleiste .eintrag:last-child::after { display: none; }
.zeitleiste .eintrag .typ { font-weight: 600; font-size: 13px; }
.zeitleiste .eintrag .wann { font-size: 12px; color: var(--muted); }
.zeitleiste .eintrag .text { font-size: 13px; color: var(--grau-600); margin-top: 2px; white-space: pre-line; }

/* Kontakt-/Adress-Einträge in der Kundenakte */
.eintrag-liste { display: flex; flex-direction: column; }
.eintrag-liste > div {
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.eintrag-liste > div:first-child { padding-top: 0; }
.eintrag-liste > div:last-child { border-bottom: none; padding-bottom: 0; }

/* Kleine Chips (Kategorie, ABC, Kundennummer im Kopf) */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 500; color: var(--grau-600);
  background: #fff;
}
.chip.petrol { background: var(--primary-10); border-color: transparent; color: var(--primary-dunkel); }
