:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --danger: #dc2626;
  --sidebar: #1e2a3a;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 220px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
}
#sidebar .logo {
  font-size: 22px; font-weight: 700; color: #fff;
  padding: 20px 18px 14px;
  letter-spacing: .5px;
}
#sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; }
#sidebar nav button {
  background: none; border: none; color: var(--sidebar-text);
  text-align: left; padding: 10px 12px; border-radius: 8px;
  font-size: 14px; cursor: pointer;
}
#sidebar nav button:hover { background: rgba(255,255,255,.08); color: #fff; }
#sidebar nav button.active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 16px 18px; font-size: 11px; color: #64748b; line-height: 1.5; }

/* ---------- Main ---------- */
main { flex: 1; margin-left: 220px; display: flex; flex-direction: column; min-height: 100vh; }

#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
#searchbox { position: relative; flex: 1; max-width: 480px; }
#search-input {
  width: 100%; padding: 9px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none; background: var(--bg);
}
#search-input:focus { border-color: var(--accent); background: #fff; }
#search-results {
  position: absolute; top: 42px; left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12); max-height: 420px; overflow: auto; z-index: 50;
}
#search-results .sr-group { padding: 8px 12px 4px; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
#search-results .sr-item { display: block; width: 100%; text-align: left; padding: 8px 12px; border: none; background: none; cursor: pointer; font-size: 13px; }
#search-results .sr-item:hover { background: #eff6ff; }
#search-results .sr-item small { color: var(--muted); display: block; }
#header-actions { margin-left: auto; display: flex; gap: 8px; }

#content { padding: 24px; flex: 1; }

/* ---------- Karten & Layout ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h3 { font-size: 15px; }
.hint { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h2 { font-size: 20px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12px; }

.link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

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

/* ---------- Tabellen ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f8fafc; }
tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.idee { background: #fef3c7; color: #92400e; }
.badge.aktiv { background: #dcfce7; color: #166534; }
.badge.pausiert { background: #e2e8f0; color: #475569; }
.badge.abgeschlossen { background: #f1f5f9; color: #64748b; }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; }
.stat-card:hover { border-color: var(--accent); }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .lbl { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat-card.warn .num { color: #d97706; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

/* ---------- Timeline ---------- */
.timeline { margin-top: 8px; }
.tl-item { display: flex; gap: 12px; position: relative; padding-bottom: 14px; }
.tl-item::before {
  content: ''; position: absolute; left: 6px; top: 16px; bottom: 0;
  width: 2px; background: var(--border);
}
.tl-item:last-child::before { display: none; }
.tl-dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 3px; flex-shrink: 0; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border); z-index: 1; }
.t-note { background: #94a3b8; }
.t-call { background: #3b82f6; }
.t-email { background: #14b8a6; }
.t-meeting { background: #a855f7; }
.t-task { background: #f59e0b; }
.t-document { background: #22c55e; }
.t-event { background: #ec4899; }
.t-project { background: #6366f1; }
.tl-card { flex: 1; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.tl-card.done { opacity: .55; }
.tl-card.done .tl-title { text-decoration: line-through; }
.tl-head { display: flex; justify-content: space-between; gap: 10px; }
.tl-title { font-weight: 600; font-size: 13px; }
.tl-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tl-desc { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: pre-wrap; }
.tl-meta { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.tl-type { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tl-meta label.chk { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); cursor: pointer; }

/* ---------- Detailansicht ---------- */
.detail-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.company-logo {
  width: 56px; height: 56px; border-radius: 10px; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; background: #fff; overflow: hidden; flex-shrink: 0;
}
.company-logo img { max-width: 48px; max-height: 48px; object-fit: contain; }
.company-logo .fallback { font-weight: 700; color: var(--muted); font-size: 18px; }
.detail-head h2 { font-size: 22px; }
.detail-head .sub { color: var(--muted); margin-top: 2px; }
.head-actions { margin-left: auto; display: flex; gap: 8px; }

.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { word-break: break-word; }

.mini-list { list-style: none; }
.mini-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.mini-list li:last-child { border-bottom: none; }

.doc-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.doc-row:last-child { border-bottom: none; }
.doc-row .doc-name { font-weight: 600; }
.doc-row .doc-meta { color: var(--muted); font-size: 11px; }

/* ---------- Formulare ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label.fld { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.fld input, label.fld select, label.fld textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 13px; font-family: inherit; color: var(--text); background: #fff; outline: none;
}
label.fld input:focus, label.fld select:focus, label.fld textarea:focus { border-color: var(--accent); }
label.fld textarea { resize: vertical; min-height: 60px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px; background: #f8fafc; border: 1px dashed var(--border); border-radius: 8px; margin-bottom: 14px; }
.inline-form input, .inline-form select {
  padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; font-family: inherit; outline: none;
}

/* ---------- Modal & Toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 100;
}
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: 85vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; overflow: auto; }

#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1e293b; color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: slidein .2s ease; }
.toast.error { background: var(--danger); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Graph ---------- */
.graph-card { padding: 12px; }
#graph-container { height: calc(100vh - 180px); min-height: 400px; }

.hidden { display: none !important; }
