/* =====================================================================
   Victoris CRM — Design-System
   Professioneller Agentur-Look. Marke zentral über Tokens austauschbar.
   ===================================================================== */
:root {
  /* Marke (hier später echte Firmenfarben eintragen) */
  --brand:        #0b5cff;
  --brand-600:    #0a4fd8;
  --brand-050:    #eaf1ff;
  --ink:          #0f1b2d;
  --ink-2:        #33455c;
  --muted:        #6b7c93;
  --line:         #e3e9f1;
  --line-2:       #eef2f7;
  --surface:      #ffffff;
  --surface-2:    #f6f8fb;
  --surface-3:    #eef2f7;
  --bg:           #f1f4f9;

  /* Status-Farben (Pipeline) */
  --st-erst:      #6366f1;
  --st-qual:      #0ea5e9;
  --st-vertrag:   #f59e0b;
  --st-laufen:    #10b981;
  --st-abschluss: #64748b;

  /* Semantik */
  --danger:       #dc2626;
  --danger-bg:    #fdecec;
  --warn:         #b45309;
  --warn-bg:      #fef3e2;
  --ok:           #067647;
  --ok-bg:        #e6f6ee;

  --radius:       12px;
  --radius-sm:    8px;
  --shadow-sm:    0 1px 2px rgba(16,27,45,.06), 0 1px 3px rgba(16,27,45,.05);
  --shadow-md:    0 10px 30px rgba(16,27,45,.12);
  --shadow-lg:    0 24px 60px rgba(16,27,45,.22);
  --sidebar-w:    244px;
  --font:         "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink);
  background: var(--bg); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; color: var(--ink); letter-spacing: -.01em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
  padding: .5rem .9rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; background: var(--surface-3); color: var(--ink-2);
  transition: background .15s, box-shadow .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { background: var(--line); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.sm { padding: .32rem .6rem; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  width: 30px; height: 30px; border-radius: 7px; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

/* ---------- Inputs ---------- */
.input, select.input, textarea.input {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font: inherit; color: var(--ink); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-050);
}
textarea.input { resize: vertical; min-height: 62px; }
label.fld { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: .3rem; }
.field { margin-bottom: .85rem; }
.chk { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------- Badges / Pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .35rem; padding: .18rem .5rem;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--ink-2);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-Erstkontakt { color: var(--st-erst); background: color-mix(in srgb, var(--st-erst) 12%, white); }
.st-Qualifiziert { color: var(--st-qual); background: color-mix(in srgb, var(--st-qual) 12%, white); }
.st-Vertrag { color: var(--st-vertrag); background: color-mix(in srgb, var(--st-vertrag) 15%, white); }
.st-Am-Laufen { color: var(--st-laufen); background: color-mix(in srgb, var(--st-laufen) 14%, white); }
.st-Abgeschlossen { color: var(--st-abschluss); background: color-mix(in srgb, var(--st-abschluss) 14%, white); }
.prio-Hoch { color: var(--danger); background: var(--danger-bg); }
.prio-Mittel { color: var(--warn); background: var(--warn-bg); }
.prio-Niedrig { color: var(--muted); background: var(--surface-3); }
.pill-over { color: var(--danger); background: var(--danger-bg); }
.pill-due { color: var(--warn); background: var(--warn-bg); }

/* =====================================================================
   Login / 2FA / Setup — zentrierte Karte
   ===================================================================== */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(1200px 500px at 80% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent),
    var(--bg);
}
.auth-card {
  width: min(400px, 94vw); background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-md); padding: 2rem 1.9rem; border: 1px solid var(--line-2);
}
.brand-mark {
  width: 44px; height: 44px; border-radius: 11px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 22px; margin-bottom: 1rem;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 40%, transparent);
}
.auth-card h1 { font-size: 1.25rem; }
.auth-card .sub { color: var(--muted); margin: .2rem 0 1.3rem; }
.auth-card .field:last-of-type { margin-bottom: 1.2rem; }
.auth-error { background: var(--danger-bg); color: var(--danger); padding: .6rem .75rem; border-radius: 8px; font-size: 12.5px; margin-bottom: 1rem; }
.auth-note { background: var(--warn-bg); color: var(--warn); padding: .6rem .75rem; border-radius: 8px; font-size: 12.5px; margin-bottom: 1rem; }

/* 2FA-Setup */
.qr-box { display: grid; place-items: center; padding: 1rem; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--line); }
.qr-box svg { width: 190px; height: 190px; }
.secret-chip { font-family: "SF Mono", ui-monospace, monospace; letter-spacing: 2px; background: var(--surface-3); padding: .5rem .7rem; border-radius: 8px; text-align: center; font-size: 14px; word-break: break-all; }
.recovery-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin: .8rem 0; }
.recovery-grid code { background: var(--surface-3); padding: .4rem; border-radius: 6px; text-align: center; font-size: 13px; }

/* =====================================================================
   App-Layout
   ===================================================================== */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #cdd7e4; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.1rem; font-weight: 700; color: #fff; font-size: 15px; }
.sidebar .logo .brand-mark { width: 30px; height: 30px; font-size: 16px; margin: 0; box-shadow: none; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: .5rem .6rem; overflow-y: auto; flex: 1; }
.nav-sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6b7d94; padding: .9rem .7rem .3rem; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .55rem .7rem; border-radius: 8px; color: #cdd7e4; font-weight: 550; font-size: 13.5px; cursor: pointer;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a .count { font-size: 11px; background: rgba(255,255,255,.14); padding: .05rem .4rem; border-radius: 999px; }
.nav a.active .count { background: rgba(255,255,255,.25); }
.sidebar .foot { padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar .foot .u { color: #fff; font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .8rem 1.4rem; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.05rem; }
.topbar .spacer { flex: 1; }
.search { position: relative; }
.search .input { width: 240px; padding-left: 2rem; }
.search::before { content: "⌕"; position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.content { padding: 1.4rem; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card .card-head { display: flex; align-items: center; gap: .6rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line-2); }
.card .card-head h3 { font-size: 14px; }
.card .card-body { padding: 1.1rem; }
.grid { display: grid; gap: 1.1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Dashboard ---------- */
.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: .8rem; }
.pipe-card { border-radius: var(--radius); padding: 1rem; cursor: pointer; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s; }
.pipe-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.pipe-card .n { font-size: 1.9rem; font-weight: 750; letter-spacing: -.02em; }
.pipe-card .l { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
.kpi { display: flex; flex-direction: column; gap: .1rem; }
.kpi .v { font-size: 1.5rem; font-weight: 750; }
.kpi .k { font-size: 12px; color: var(--muted); }
.stat-row { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.stat-row:last-child { border-bottom: 0; }
.action-item { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.action-item:hover { background: var(--surface-2); }
.action-item:last-child { border-bottom: 0; }
.action-item .when { font-size: 12px; margin-left: auto; }
.feed-item { display: flex; gap: .6rem; padding: .45rem 0; font-size: 12.5px; color: var(--ink-2); border-bottom: 1px solid var(--line-2); }
.feed-item:last-child { border-bottom: 0; }

/* ---------- Tabelle / Listen ---------- */
.toolbar { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
table.grid-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid-tbl thead th {
  text-align: left; padding: .65rem .8rem; background: var(--surface-2); color: var(--muted);
  font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none;
}
.grid-tbl thead th:hover { color: var(--ink); }
.grid-tbl tbody td { padding: .6rem .8rem; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.grid-tbl tbody tr { cursor: pointer; }
.grid-tbl tbody tr:hover { background: var(--brand-050); }
.grid-tbl tbody tr:last-child td { border-bottom: 0; }
.dup-flag { color: var(--warn); margin-left: .3rem; }
.pager { display: flex; align-items: center; gap: .6rem; justify-content: flex-end; margin-top: .9rem; font-size: 13px; }
.progress { position: relative; height: 7px; border-radius: 999px; background: var(--surface-3); width: 90px; overflow: hidden; }
.progress > span { position: absolute; inset: 0 auto 0 0; background: var(--st-vertrag); border-radius: 999px; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* =====================================================================
   Modal / Detail-Overlay
   ===================================================================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16,27,45,.5); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 1.2rem; z-index: 100; animation: fade .18s ease;
}
.modal-overlay.closing { animation: fade .18s ease reverse; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(560px, 96vw); max-height: 92vh; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; animation: pop .18s ease;
}
.modal-card.wide { width: min(880px, 96vw); }
.modal-card.detail { width: min(920px, 97vw); }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { font-size: 1.05rem; flex: 1; }
.modal-body { padding: 1.2rem; overflow-y: auto; }
.modal-footer { display: flex; gap: .6rem; justify-content: flex-end; padding: .9rem 1.2rem; border-top: 1px solid var(--line-2); background: var(--surface-2); }

/* Detail-Sektionen */
.detail-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: .3rem; }
.detail-head .id { font-size: 12px; color: var(--muted); }
.section { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; }
.section > .sec-head { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; background: var(--surface-2); cursor: pointer; font-weight: 650; font-size: 13px; }
.section > .sec-head .chev { margin-left: auto; color: var(--muted); transition: transform .15s; }
.section.collapsed > .sec-head .chev { transform: rotate(-90deg); }
.section .sec-body { padding: 1rem; }
.section.locked .sec-body { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, #fff 10px, #fff 20px); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .9rem; }
.form-grid .field.full { grid-column: 1 / -1; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: .3rem .8rem; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.lock-note { display: flex; align-items: center; gap: .5rem; font-size: 12px; color: var(--warn); margin-bottom: .6rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .7rem; padding: .4rem 0; font-size: 12.5px; }
.timeline .marker { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); margin-top: .35rem; flex: none; }

.contact-row { display: flex; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.contact-row:last-child { border-bottom: 0; }
.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; }

/* Multiselect (Leistungsart) */
.multi { display: flex; flex-wrap: wrap; gap: .4rem; }
.multi label { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; cursor: pointer; }
.multi label.on { background: var(--brand-050); border-color: var(--brand); color: var(--brand-600); }
.multi input { display: none; }

/* Segmented / Tabs (Einstellungen) */
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1.2rem; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: .6rem .9rem; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Toasts ---------- */
.toast-host { position: fixed; right: 1.2rem; bottom: 1.2rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow-md); font-size: 13px; opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; max-width: 340px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Loader ---------- */
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; z-index: 90; width: 260px; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex !important; }
  .search .input { width: 150px; }
  .form-grid, .grid.cols-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
.menu-toggle { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; }
