/* =========================================================
   ManiDesign Klient-System — Design System v2
   Ein System, überall gleich: Farben, Abstände, Komponenten.
   ========================================================= */

:root {
  color-scheme: dark;
  /* Farben */
  --bg: #0b0d12;
  --bg-soft: #10131b;
  --surface: #151924;
  --surface-2: #1b2030;
  --border: #262c3d;
  --border-soft: #1e2331;
  --text: #eef0f6;
  --text-muted: #9aa3b8;
  --text-faint: #666f88;

  --primary: #6c5ce7;
  --primary-hover: #5a4bd1;
  --primary-contrast: #ffffff;
  --primary-soft: rgba(108, 92, 231, 0.14);

  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.14);

  /* Abstände (ein Rhythmus, überall) */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* Typografie */
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --text-xs: 12px; --text-sm: 13px; --text-base: 15px; --text-lg: 18px;
  --text-xl: 22px; --text-2xl: 28px; --text-3xl: 34px;

  /* Sonstiges */
  --radius-sm: 8px; --radius: 12px; --radius-lg: 16px; --radius-full: 999px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.45);
  --control-h: 44px;
  --transition: 0.15s ease;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 { font-weight: 650; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }

/* ---------- Layout shell ---------- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4) var(--space-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header .brand { display: flex; align-items: center; gap: var(--space-3); }
.app-header .brand .logo-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft);
}
.app-header .brand-name { font-weight: 700; font-size: var(--text-lg); }
.app-header .brand-sub { color: var(--text-faint); font-size: var(--text-xs); }
.app-header nav { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.app-nav-link {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: var(--transition);
}
.app-nav-link:hover { color: var(--text); background: var(--surface-2); }
.app-nav-link.active { color: var(--primary-contrast); background: var(--primary); }
.header-right { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }

.container {
  max-width: 1400px;
  margin: var(--space-8) auto;
  padding: 0 var(--space-6);
}
.page-title-row {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap;
}
.page-title-row p { color: var(--text-muted); margin-top: var(--space-1); }

/* ---------- Buttons (ein System) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-h);
  padding: 0 var(--space-5);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { height: 34px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon { width: var(--control-h); height: var(--control-h); padding: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
}
.card + .card { margin-top: var(--space-4); }
.card-title { font-size: var(--text-lg); font-weight: 650; margin-bottom: var(--space-1); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }

/* ---------- Forms (ein System) ---------- */
.field { margin-bottom: var(--space-4); }
.field label {
  display: block; font-size: var(--text-sm); font-weight: 600;
  color: var(--text-muted); margin-bottom: var(--space-2);
}
.field .hint { font-size: var(--text-xs); color: var(--text-faint); margin-top: var(--space-1); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="number"], input[type="date"], input[type="url"], input[type="tel"], input:not([type]), select, textarea {
  width: 100%;
  height: var(--control-h);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0 var(--space-4);
  font-size: var(--text-base);
  font-family: var(--font);
  transition: var(--transition);
}
textarea { height: auto; min-height: 120px; padding: var(--space-3) var(--space-4); resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
code, pre, .code-font { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; }

/* ---------- Badges / Tags ---------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 3px var(--space-3); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 650;
}
.badge-primary { background: var(--primary-soft); color: #b3a6ff; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--surface-2); color: var(--text-muted); }

/* ---------- Tabs (ein System) ---------- */
.tabs {
  display: flex; gap: var(--space-1); margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tab {
  padding: var(--space-3) var(--space-5);
  background: none; border: none; cursor: pointer;
  font-size: var(--text-sm); font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
  transition: var(--transition);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-contrast); color: var(--text); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---------- Table (ein System) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.ds-table { width: 100%; border-collapse: collapse; background: var(--surface); }
table.ds-table th {
  text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border);
}
table.ds-table td { padding: var(--space-4); border-bottom: 1px solid var(--border-soft); font-size: var(--text-sm); }
table.ds-table tr:last-child td { border-bottom: none; }
table.ds-table tr:hover td { background: var(--surface-2); }
.table-empty { text-align: center; color: var(--text-faint); padding: var(--space-10); }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(5,6,10,0.7);
  align-items: center; justify-content: center; z-index: 100; padding: var(--space-4);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto;
  padding: var(--space-8);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-6); }

/* ---------- Auth pages (Login) ---------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: var(--space-6);
  background:
    radial-gradient(1200px 600px at 15% 10%, rgba(108,92,231,0.20), transparent 60%),
    radial-gradient(900px 500px at 85% 90%, rgba(56,189,248,0.14), transparent 60%),
    var(--bg);
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; padding: var(--space-10) var(--space-8);
}
.auth-brand { display: flex; align-items: center; gap: var(--space-3); justify-content: center; margin-bottom: var(--space-6); }
.auth-brand .logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 6px var(--primary-soft); }
.auth-card h1 { text-align: center; font-size: var(--text-xl); }
.auth-card .subtitle { text-align: center; color: var(--text-muted); font-size: var(--text-sm); margin: var(--space-2) 0 var(--space-6); }
.auth-footer { text-align: center; margin-top: var(--space-6); font-size: var(--text-sm); color: var(--text-faint); }
.alert { border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); font-size: var(--text-sm); margin-bottom: var(--space-4); }
.alert-danger { background: var(--danger-soft); color: #ff8f8f; border: 1px solid rgba(239,68,68,0.3); }
.alert-success { background: var(--success-soft); color: #7ee6a3; border: 1px solid rgba(34,197,94,0.3); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }

@media (max-width: 640px) {
  .app-header { padding: var(--space-4); }
  .container { padding: 0 var(--space-4); }
}

/* =========================================================
   Erweiterungen v3 – Verträge, Rechnungen, Abnahme
   ========================================================= */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
@media (max-width: 860px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: var(--space-3); }
.section-title { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 700; margin: var(--space-6) 0 var(--space-3); }
.alert-info { background: var(--info-soft); color: #9edcff; border: 1px solid rgba(56,189,248,0.3); }
.alert-warning { background: var(--warning-soft); color: #fcd28b; border: 1px solid rgba(245,158,11,0.3); }
.muted-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-4); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px var(--space-4); font-size: var(--text-sm); }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-6); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4) var(--space-5); }
.stat-card .label { font-size: var(--text-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.stat-card .value { font-size: var(--text-xl); font-weight: 750; margin-top: 4px; }

/* Positions-Editor */
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th { text-align: left; font-size: var(--text-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; padding: 6px; border-bottom: 1px solid var(--border); }
.edit-table td { padding: 6px; vertical-align: top; border-bottom: 1px solid var(--border-soft); }
.edit-table input, .edit-table select, .edit-table textarea { height: 36px; font-size: var(--text-sm); padding: 0 10px; }
.edit-table textarea { min-height: 54px; height: 54px; padding: 8px 10px; margin-top: 6px; }
.edit-table .num { text-align: right; white-space: nowrap; }
.edit-table .w-qty { width: 80px; } .edit-table .w-unit { width: 100px; } .edit-table .w-price { width: 120px; } .edit-table .w-bill { width: 120px; }
.price-dev { font-size: var(--text-xs); color: var(--warning); margin-top: 4px; }
.price-std { font-size: var(--text-xs); color: var(--text-faint); margin-top: 4px; }
.table-scroll { overflow-x: auto; }

/* Bausteine */
.clause { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: var(--space-3); }
.clause-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); cursor: pointer; }
.clause-head .title { flex: 1; font-weight: 600; font-size: var(--text-sm); }
.clause-head .num { color: var(--text-faint); font-size: var(--text-xs); min-width: 28px; }
.clause.disabled { opacity: .55; }
.clause-body { display: none; padding: 0 var(--space-4) var(--space-4); }
.clause.open .clause-body { display: block; }
.clause-body textarea { min-height: 200px; font-family: var(--font); font-size: var(--text-sm); line-height: 1.6; }
.switch { position: relative; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(16px); }

/* Totals */
.totals-box { margin-left: auto; min-width: 280px; max-width: 360px; }
.totals-box .line { display: flex; justify-content: space-between; padding: 4px 0; font-size: var(--text-sm); color: var(--text-muted); }
.totals-box .line.grand { color: var(--text); font-weight: 750; font-size: var(--text-lg); border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }

/* Toasts */
#toast-box { position: fixed; right: 20px; bottom: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--info); color: var(--text); padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: var(--text-sm); opacity: 0; transform: translateY(8px); transition: .2s; white-space: pre-line; }
.toast.show { opacity: 1; transform: none; }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 var(--space-4) var(--space-6); font-size: var(--text-sm); }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--text-faint); font-size: var(--text-xs); }

/* Signatur */
.signature-canvas { border: 2px dashed var(--border); border-radius: var(--radius); background: #fff; cursor: crosshair; display: block; width: 100%; height: 190px; touch-action: none; }
.check-item { display: flex; gap: var(--space-3); align-items: flex-start; margin-bottom: var(--space-3); font-size: var(--text-sm); }
.check-item input { width: 20px; height: 20px; margin-top: 2px; flex-shrink: 0; accent-color: var(--primary); }
.check-item.required label::after { content: " *"; color: var(--danger); }
.paper { background: #fff; color: #1e293b; border-radius: var(--radius); border: 1px solid var(--border); max-height: 520px; overflow-y: auto; }
.paper .doc { margin: 0; box-shadow: none; padding: 32px 36px; }
.radio-card { display: flex; gap: var(--space-3); align-items: flex-start; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-4); cursor: pointer; margin-bottom: var(--space-3); background: var(--surface-2); }
.radio-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.radio-card input { margin-top: 3px; accent-color: var(--primary); }
.radio-card strong { display: block; margin-bottom: 2px; }
.radio-card small { color: var(--text-muted); }
.list-input .li { display: flex; gap: var(--space-2); margin-bottom: var(--space-2); }
.list-input .li input, .list-input .li textarea { flex: 1; }
.badge-big { font-size: var(--text-sm); padding: 6px 14px; }

/* ---------- Admin-Header: Navigation + Profil-Menü ---------- */
.app-header .main-nav { display: flex; gap: var(--space-1); flex-wrap: wrap; flex: 1; justify-content: center; }
.profile-menu { position: relative; }
.profile-trigger {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-full); padding: 4px 12px 4px 4px; cursor: pointer;
  font-family: var(--font); font-size: var(--text-sm); font-weight: 600; transition: var(--transition);
}
.profile-trigger:hover { border-color: var(--primary); }
.profile-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
}
.profile-trigger-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-trigger-chevron { color: var(--text-faint); font-size: 12px; }
.profile-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 8px); min-width: 260px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: var(--space-2);
}
.profile-menu.open .profile-dropdown { display: block; }
.profile-dropdown-header { padding: var(--space-3); }
.profile-dropdown-header .name { font-weight: 650; }
.profile-dropdown-header .email { font-size: var(--text-xs); color: var(--text-faint); }
.profile-dropdown-label { padding: var(--space-2) var(--space-3) 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 700; }
.profile-dropdown-divider { height: 1px; background: var(--border); margin: var(--space-2) 0; }
.profile-dropdown-link {
  display: block; width: 100%; text-align: left; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); color: var(--text-muted); font-size: var(--text-sm);
  background: none; border: 0; cursor: pointer; font-family: var(--font);
}
.profile-dropdown-link:hover, .profile-dropdown-link.active { background: var(--surface-2); color: var(--text); }
.profile-dropdown-link.danger { color: var(--danger); }
@media (max-width: 860px) {
  .app-header .main-nav { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .profile-trigger-name { display: none; }
}
