/* ═══════════════════════════════════════════════════════════════════
   Ainuity — Design-System
   Tokens und Basis-Komponenten 1:1 aus design-referenz/ainuity-crm.html.
   Light/Dark über [data-theme] am <html>; Default folgt dem System.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #F6F6F7;
  --surface: #FFFFFF;
  --surface-2: #FAFAFB;
  --surface-hover: #F0F0F2;
  --border: rgba(20, 20, 25, 0.08);
  --border-strong: rgba(20, 20, 25, 0.14);
  --text: #17181C;
  --text-2: #6B6F76;
  --text-3: #9A9EA6;
  --accent: #5E6AD2;
  --accent-hover: #4E59C4;
  --accent-soft: rgba(94, 106, 210, 0.10);
  --accent-soft-strong: rgba(94, 106, 210, 0.18);
  --success: #1DA75A;
  --success-soft: rgba(29, 167, 90, 0.12);
  --danger: #E5484D;
  --danger-soft: rgba(229, 72, 77, 0.12);
  --warning: #EAA100;
  --warning-soft: rgba(234, 161, 0, 0.14);
  --info: #3B82F6;
  --info-soft: rgba(59, 130, 246, 0.12);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 25, 0.05);
  --shadow-md: 0 8px 24px rgba(20, 20, 25, 0.10);
  --shadow-lg: 0 16px 48px rgba(20, 20, 25, 0.18);
  --sidebar-w: 236px;
  color-scheme: light;
}

[data-theme='dark'] {
  --bg: #0D0E11;
  --surface: #17181C;
  --surface-2: #1C1D22;
  --surface-hover: #222329;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #F1F2F4;
  --text-2: #9A9EA6;
  --text-3: #6B6F76;
  --accent: #7C87E8;
  --accent-hover: #8D97EC;
  --accent-soft: rgba(124, 135, 232, 0.16);
  --accent-soft-strong: rgba(124, 135, 232, 0.26);
  --success: #33C173;
  --success-soft: rgba(51, 193, 115, 0.16);
  --danger: #F16F73;
  --danger-soft: rgba(241, 111, 115, 0.16);
  --warning: #F3B93B;
  --warning-soft: rgba(243, 185, 59, 0.18);
  --info: #5B9CF6;
  --info-soft: rgba(91, 156, 246, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

.icon {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(94, 106, 210, 0.35); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; }

/* ── Formularfelder ── */
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field-input, .field-select, .field-textarea {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 11px; font-size: 13.5px; color: var(--text);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-input::placeholder { color: var(--text-3); }
.field-textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }

/* ── Panels & Tabellen ── */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h3 { font-size: 13.5px; font-weight: 700; }
.panel-body { padding: 16px 18px; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .4px;
  padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 16px; font-size: 13px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable:hover { background: var(--surface-hover); cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 100px; font-size: 11px; font-weight: 600; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.tag { display: inline-flex; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin: 1px; }

/* ── Meldungen ── */
.alert { padding: 10px 13px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 500; margin-bottom: 14px; border: 1px solid transparent; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: var(--info); }

.empty-state { text-align: center; padding: 44px 20px; color: var(--text-3); }
.empty-state h4 { font-size: 14px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.empty-state p { font-size: 12.5px; max-width: 40ch; margin: 0 auto; }

/* ── App-Shell: Sidebar + Topbar (Aufbau aus der Referenz) ── */
.crm-body { height: 100vh; overflow: hidden; }
.app { display: flex; height: 100vh; }

.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sb-head { padding: 16px 16px 12px; display: flex; align-items: center; gap: 10px; }
.sb-logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #8B7CF0); display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.sb-logo svg { width: 16px; height: 16px; stroke: #fff; }
.sb-name { font-weight: 700; font-size: 14.5px; letter-spacing: -0.2px; }
.sb-sub { font-size: 10.5px; color: var(--text-3); font-weight: 500; letter-spacing: 0.4px; text-transform: uppercase; margin-top: 1px; }

.sb-nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
.sb-sec { font-size: 10px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-3); padding: 14px 8px 6px; }
.ni { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 9px; border-radius: var(--radius-sm); border: none; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500; margin-bottom: 1px; text-decoration: none; }
.ni svg { opacity: 0.75; }
.ni:hover { background: var(--surface-hover); color: var(--text); }
.ni.active { background: var(--accent-soft); color: var(--accent); }
.ni.active svg { opacity: 1; stroke: var(--accent); }
.ni-soon { color: var(--text-3); cursor: default; }
.ni-soon:hover { background: transparent; color: var(--text-3); }
.ni-soon-tag { margin-left: auto; font-size: 9.5px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--text-3); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; }

.sb-foot { padding: 10px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft-strong); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.sb-user { flex: 1; min-width: 0; }
.sb-user-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { font-size: 11px; color: var(--text-3); }
.icon-btn { width: 28px; height: 28px; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; display: flex; align-items: center; justify-content: center; color: var(--text-2); flex-shrink: 0; }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar { min-height: 56px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 22px; border-bottom: 1px solid var(--border); }
.topbar-title { font-size: 15.5px; font-weight: 700; letter-spacing: -0.2px; }
.topbar-sub { font-size: 12px; color: var(--text-3); font-weight: 500; margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.content { flex: 1; overflow-y: auto; padding: 24px 28px 60px; }
.content-narrow { max-width: 760px; }

.section-stack { display: flex; flex-direction: column; gap: 18px; }
.section-title { font-size: 12.5px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; color: var(--text-3); margin-bottom: 2px; }

@media (max-width: 820px) {
  .crm-body { height: auto; overflow: auto; }
  .app { flex-direction: column; height: auto; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .sb-nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sb-sec { width: 100%; padding: 8px 8px 2px; }
  .main { overflow: visible; }
  .content { overflow: visible; padding: 18px 16px 48px; }
}

/* ── Kennzahlen-Kacheln ── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; }
.kpi-label { font-size: 12px; color: var(--text-2); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-label svg { width: 14px; height: 14px; opacity: .7; }
.kpi-value { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; margin-top: 8px; }
.kpi-hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }

/* ── Ansichts-Umschalter ── */
.view-toggle { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.vt-btn { padding: 5px 11px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.vt-btn:hover { color: var(--text); }
.vt-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ── Pipeline-Board ── */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: 258px; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.board-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 10px; min-height: 130px; }
.board-head { display: flex; align-items: center; gap: 7px; padding: 2px 4px; }
.board-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.board-title { font-size: 12.5px; font-weight: 700; flex: 1; }
.board-count { font-size: 11.5px; font-weight: 700; color: var(--text-3); }
.board-sum { font-size: 11px; color: var(--text-3); padding: 2px 4px 8px; font-family: 'JetBrains Mono', ui-monospace, monospace; min-height: 20px; }
.board-drop { display: flex; flex-direction: column; gap: 8px; min-height: 60px; border-radius: 8px; transition: background .12s, outline-color .12s; outline: 2px dashed transparent; outline-offset: -2px; }
.board-drop.over { background: var(--accent-soft); outline-color: var(--accent); }

.deal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 12px; cursor: grab; box-shadow: var(--shadow-sm); }
.deal-card:active { cursor: grabbing; }
.deal-card.dragging { opacity: .45; }
.deal-card.saving { opacity: .6; pointer-events: none; }
.deal-card-title { display: block; font-size: 13px; font-weight: 600; line-height: 1.35; }
.deal-card-title:hover { color: var(--accent); }
.deal-card-sub { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.deal-card-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.deal-value { font-size: 11.5px; font-weight: 700; color: var(--success); font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* ── Dialoge ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(13, 14, 17, .48); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 14.5px; font-weight: 700; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--border); }

/* ── Detailseiten ── */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.detail-title { font-size: 20px; font-weight: 800; letter-spacing: -0.3px; }
.detail-sub { font-size: 13px; color: var(--text-3); margin-top: 3px; }
.dl { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 9px 14px; font-size: 13px; }
.dl dt { color: var(--text-3); font-weight: 600; font-size: 12px; padding-top: 1px; }
.dl dd { margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-3); margin-bottom: 12px; }
.back-link:hover { color: var(--text); }

/* ── Zeitleiste ── */
.timeline { display: flex; flex-direction: column; }
.tl-item { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--text-3); }
.tl-dot svg { width: 13px; height: 13px; }
.tl-body { min-width: 0; flex: 1; }
.tl-text { font-size: 13px; line-height: 1.45; }
.tl-meta { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.tl-note { white-space: pre-wrap; }

/* ── Aufgabenliste ── */
.task-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: none; }
.task-check { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--border-strong); background: var(--surface); flex-shrink: 0; margin-top: 1px; display: flex; align-items: center; justify-content: center; padding: 0; }
.task-check:hover { border-color: var(--accent); }
.task-check svg { width: 12px; height: 12px; opacity: 0; stroke: #fff; stroke-width: 3; }
.task-check.done { background: var(--success); border-color: var(--success); }
.task-check.done svg { opacity: 1; }
.task-title { font-size: 13px; line-height: 1.4; }
.task-done .task-title { text-decoration: line-through; color: var(--text-3); }
.task-meta { font-size: 11.5px; color: var(--text-3); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.task-overdue { color: var(--danger); font-weight: 600; }

/* ── Stufen-Balken (Dashboard) ── */
.stage-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }
.stage-bar-row:last-child { margin-bottom: 0; }
.stage-bar-label { width: 132px; flex-shrink: 0; font-size: 12.5px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.stage-bar-track { flex: 1; height: 8px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.stage-bar-fill { height: 100%; border-radius: 5px; }
.stage-bar-val { width: 92px; flex-shrink: 0; text-align: right; font-size: 12px; font-weight: 700; font-family: 'JetBrains Mono', ui-monospace, monospace; }

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dt { padding-top: 8px; }
}

.link-row { margin-bottom: 4px; }
.link-row .field-input { font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── Login / zentrierte Karten ── */
.center-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.center-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 30px 28px; box-shadow: var(--shadow-md); }
.brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #8B7CF0); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 14px; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.brand-name { font-weight: 800; font-size: 15px; letter-spacing: -.2px; }
.brand-sub { font-size: 10.5px; color: var(--text-3); font-weight: 600; letter-spacing: .4px; text-transform: uppercase; margin-top: 1px; }
.center-card h1 { font-size: 18px; font-weight: 800; letter-spacing: -.3px; margin-bottom: 6px; }
.center-card .sub { font-size: 12.5px; color: var(--text-2); margin-bottom: 20px; }
