:root {
  --bg: #13121f;
  --bg2: #1a1929;
  --bg3: #222134;
  --surface: #1e1d2e;
  --border: rgba(167,139,250,0.12);
  --border-hover: rgba(167,139,250,0.28);
  --fg: #e8e4f5;
  --fg-muted: #9085a8;
  --fg-dim: #55526a;
  --accent: #7c5cd6;
  --accent-hi: #a78bfa;
  --accent-lo: rgba(124,92,214,0.14);
  --red: #e05c6a;
  --green: #2fa968;
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 244px;
  --font-mono: 'DM Mono', ui-monospace, 'Courier New', monospace;
  --font-display: 'Unbounded', Arial, sans-serif;
  --border-faint: rgba(167,139,250,0.06);
  --border-dashed: rgba(167,139,250,0.25);
}

/* ── Helles Design ────────────────────────────────────────────────
   Nur die Farben werden getauscht, alles andere (Radien, Abstaende,
   Schriften) bleibt — sonst waeren es zwei Layouts statt zwei Anstrichen.
   Kontraste sind gegen den hellen Hintergrund nachgezogen: die dunklen
   Akzenttoene sind auf Weiss zu blass. */
:root[data-theme="light"] {
  --bg: #f4f2f8;
  --bg2: #ffffff;
  --bg3: #eeebf5;
  --surface: #ffffff;
  --border: rgba(60,40,110,0.14);
  --border-hover: rgba(60,40,110,0.30);
  --fg: #1c1b29;
  --fg-muted: #5e5a70;
  --fg-dim: #8c88a0;
  --accent: #6a45c9;
  --accent-hi: #5b34c0;
  --accent-lo: rgba(124,92,214,0.10);
  --red: #c0392f;
  --green: #1d7a48;
  --border-faint: rgba(60,40,110,0.07);
  --border-dashed: rgba(60,40,110,0.26);
}

/* Ohne ausdrueckliche Wahl dem System folgen. data-theme setzt der
   Umschalter und gewinnt dadurch gegen diese Regel. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f2f8;
    --bg2: #ffffff;
    --bg3: #eeebf5;
    --surface: #ffffff;
    --border: rgba(60,40,110,0.14);
    --border-hover: rgba(60,40,110,0.30);
    --fg: #1c1b29;
    --fg-muted: #5e5a70;
    --fg-dim: #8c88a0;
    --accent: #6a45c9;
    --accent-hi: #5b34c0;
    --accent-lo: rgba(124,92,214,0.10);
    --red: #c0392f;
    --green: #1d7a48;
    --border-faint: rgba(60,40,110,0.07);
    --border-dashed: rgba(60,40,110,0.26);
  }
}

/* ── Anmeldeseite ─────────────────────────────────────────────────
   Erste Seite, die jemand sieht — sie trägt den Markenauftritt, nicht die
   nackte Formularkarte. Der Kopfbereich ist bewusst immer dunkel, auch im
   hellen Design: das ist das Erkennungszeichen der Suite. */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
}
.login-card {
  width: 340px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(10, 6, 25, 0.35);
}
.login-head {
  background: #13121f;
  padding: 26px 26px 22px;
  display: flex;
  align-items: center;
  gap: 13px;
}
.login-head svg { flex-shrink: 0; }
.login-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  color: #f4f1ff;
  line-height: 1.1;
}
.login-sub {
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #a896e0;
  margin-top: 4px;
}
.login-body { padding: 22px 26px 26px; }
.login-body .field:first-child { margin-top: 0; }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--border-hover); }

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }
.app.logged-out .sidebar { display: none; }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

/* split view (form + preview) */
.split {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.split-form {
  width: 400px;
  min-width: 340px;
  overflow-y: auto;
  padding: 24px 24px;
  border-right: 1px solid var(--border);
}
.split-preview {
  flex: 1;
  background: #2a2940;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.split-preview iframe {
  flex: 1;
  border: none;
  background: #f0eef4;
}
.preview-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* ── Sidebar ── */
.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo svg { flex-shrink: 0; }
.sidebar-logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  color: var(--fg);
  letter-spacing: 0.3px;
}
.sidebar-logo-sub {
  font-size: 8px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(167,139,250,0.45);
  margin-top: 1px;
}

.sidebar-section {
  padding: 16px 10px 4px;
  font-size: 8px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: calc(100% - 12px);
  text-align: left;
}
.nav-item:hover { background: var(--accent-lo); color: var(--fg); }
.nav-item.active { background: rgba(124,92,214,0.2); color: var(--accent-hi); }
.nav-item svg { flex-shrink: 0; opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-size: 9px;
  color: var(--fg-dim);
  letter-spacing: 0.3px;
}

/* ── Topbar ── */
.topbar {
  height: 52px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 12px;
  background: var(--bg2);
}
.topbar-title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: 0.3px;
}
.topbar-sub {
  font-size: 10px;
  color: var(--fg-muted);
}
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0.3px;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-hi), var(--accent));
  color: #fff;
}
.btn-primary:hover { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--border-hover); color: var(--fg); background: var(--accent-lo); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(224,92,106,0.25);
}
.btn-danger:hover { background: rgba(224,92,106,0.1); }

.btn-sm { padding: 5px 11px; font-size: 10px; min-height: 32px; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ── Cards / Panels ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 14px; }

.panel-title {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 14px;
}

/* ── Form Controls ── */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 5px;
}

/* Jeder Eingabetyp, der im Tool vorkommt, muss hier stehen — ein fehlender
   faellt auf die Browser-Darstellung zurueck und sieht dann neben den anderen
   fremd aus. Genau so ist das Passwortfeld auf der Anmeldeseite aufgefallen. */
input[type="text"],
input[type="password"],
input[type="date"],
input[type="email"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  padding: 8px 11px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
input[readonly], input:disabled, select:disabled, textarea:disabled {
  color: var(--fg-muted);
  cursor: not-allowed;
  opacity: 0.7;
}
textarea { resize: vertical; min-height: 72px; }
select option { background: var(--bg3); }

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; margin-bottom: 0; }

/* ── Items table (positions) ── */
.items-header {
  display: grid;
  gap: 8px;
  padding: 0 0 6px;
  border-bottom: 1px solid var(--border);
  font-size: 9px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.item-row {
  display: grid;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.items-angebot .items-header,
.items-angebot .item-row { grid-template-columns: 1fr 52px 88px 88px 28px; }
.items-rechnung .items-header,
.items-rechnung .item-row { grid-template-columns: 1fr 52px 88px 28px; }

/* Regelbesteuerung: eine Spalte mehr fuer den Steuersatz pro Position. */
.items-angebot.with-tax .items-header,
.items-angebot.with-tax .item-row { grid-template-columns: 1fr 52px 88px 88px 68px 28px; }
.items-rechnung.with-tax .items-header,
.items-rechnung.with-tax .item-row { grid-template-columns: 1fr 52px 88px 68px 28px; }

.item-row input { font-size: 11px; padding: 5px 8px; }
.item-row .remove-btn {
  background: none;
  border: none;
  color: var(--fg-dim);
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.item-row .remove-btn:hover { color: var(--red); }

.add-item-btn {
  margin-top: 10px;
  font-size: 11px;
  color: var(--accent-hi);
  background: none;
  border: 1px dashed var(--border-dashed);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  width: 100%;
  transition: border-color 0.15s, background 0.15s;
}
.add-item-btn:hover { border-color: var(--accent); background: var(--accent-lo); }

/* ── Dashboard ── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-label {
  font-size: 9px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--fg);
}
.stat-sub { font-size: 10px; color: var(--fg-dim); margin-top: 3px; }

/* ── Table ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  text-align: left;
  font-size: 9px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 11px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--border-faint);
  color: var(--fg-muted);
}
.data-table td:first-child { color: var(--fg); }
.data-table tr:hover td { background: var(--accent-lo); }
.data-table .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 9px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  font-weight: 600;
}
.badge-violet { background: rgba(124,92,214,0.18); color: var(--accent-hi); }
.badge-green  { background: rgba(47,169,104,0.15); color: var(--green); }
.badge-muted  { background: rgba(144,133,168,0.12); color: var(--fg-muted); }
.badge-red    { background: rgba(224,92,106,0.15);  color: var(--red); }

/* ── Totals ── */
.totals-box {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.total-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 12px;
  color: var(--fg-muted);
}
.total-row.final {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-hi);
}

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--fg-dim);
}
.empty-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.4; }
.empty p { font-size: 12px; }

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 12px;
  color: var(--fg);
  animation: toastIn 0.2s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.success { border-color: rgba(47,169,104,0.4); color: var(--green); }
.toast.error   { border-color: rgba(224,92,106,0.4); color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(124,92,214,0.25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(124,92,214,0.45); }

/* ── Section header ── */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--fg);
}

/* ── Responsive form divider ── */
.form-section-title {
  font-size: 9px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--accent-hi);
  padding: 14px 0 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.form-section-title:first-child { border-top: none; padding-top: 0; }

/* ── Focus states (A-02) ── */
.btn:focus-visible,
.nav-item:focus-visible,
.add-item-btn:focus-visible {
  outline: 2px solid var(--accent-hi);
  outline-offset: 2px;
}

/* ── Mobile: prevent iOS auto-zoom on inputs (M-04) ── */
@media (max-width: 767px) {
  input[type="text"],
  input[type="password"],
  input[type="date"],
  input[type="email"],
  input[type="number"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px;
  }
}

/* ── Reduced motion (M-07) ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
