:root {
  --green: #00a37a;
  --green-dark: #00805f;
  --green-soft: #e6f6f1;
  --ink: #16243a;
  --muted: #64748b;
  --line: #e6eaf0;
  --bg: #f4f6f9;
  --card: #ffffff;
  --sidebar: #14233b;
  --danger: #e2483d;
  --danger-soft: #fdeceb;
  --warn: #c77700;
  --warn-soft: #fdf3e2;
  --blue: #2563eb;
  --blue-soft: #e8effe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 36, 58, 0.06), 0 6px 24px rgba(16, 36, 58, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.45; }

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 244px; flex: 0 0 244px; background: var(--sidebar); color: #cdd7e6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 16px; }
.brand-logo { font-size: 26px; background: rgba(255,255,255,.08); width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; }
.brand-name { font-weight: 800; letter-spacing: .14em; color: #fff; font-size: 16px; }
.brand-sub { font-size: 11.5px; color: #8fa2bb; letter-spacing: .03em; }
.nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: #c2cfe0; text-decoration: none; font-weight: 500; font-size: 14px; transition: .12s;
}
.nav a .nico { width: 20px; text-align: center; font-size: 16px; opacity: .92; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--green); color: #fff; box-shadow: 0 6px 18px rgba(0,163,122,.35); }
.nav a .badge { margin-left: auto; background: rgba(255,255,255,.16); color:#fff; border-radius: 999px; font-size: 11px; padding: 1px 8px; font-weight: 700; }
.nav a.active .badge { background: rgba(255,255,255,.25); }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar-foot-firma { color: #fff; font-weight: 600; }
.sidebar-foot-mail { color: #8fa2bb; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.content { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 15px;
  border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; transition: .12s;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { background: #f6f8fb; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn.danger { color: var(--danger); border-color: #f3c9c5; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef1f6; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.kpi .kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 30px; font-weight: 800; margin-top: 8px; line-height: 1; }
.kpi .kpi-sub { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.kpi .kpi-icon { float: right; font-size: 22px; opacity: .85; }
.kpi.accent { background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%); border: none; color: #fff; }
.kpi.accent .kpi-label, .kpi.accent .kpi-sub { color: rgba(255,255,255,.85); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 22px; overflow: hidden;
}
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.card-head .sub { color: var(--muted); font-size: 13px; font-weight: 400; }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th {
  text-align: left; padding: 11px 16px; color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap;
}
table.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background .1s; }
table.tbl tbody tr:hover { background: #fafbfd; }
table.tbl td .row-actions { display: flex; gap: 6px; justify-content: flex-end; opacity: 0; transition: .1s; }
table.tbl tr:hover .row-actions { opacity: 1; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.t-strong { font-weight: 600; }
.t-muted { color: var(--muted); }
.t-sm { font-size: 12.5px; }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .ic { font-size: 38px; opacity: .5; }
.empty p { margin: 12px 0 16px; }

/* ---------- Badges ---------- */
.badge-st { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-green { background: var(--green-soft); color: var(--green-dark); }
.b-gray  { background: #eef1f6; color: #475569; }
.b-blue  { background: var(--blue-soft); color: var(--blue); }
.b-warn  { background: var(--warn-soft); color: var(--warn); }
.b-red   { background: var(--danger-soft); color: var(--danger); }
.b-purple{ background: #f0e9fd; color: #7c3aed; }

/* ---------- Forms / Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 36, 58, .45); display: grid; place-items: center;
  z-index: 100; padding: 24px; animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  box-shadow: 0 24px 60px rgba(16,36,58,.3); animation: pop .16s ease;
}
.modal.wide { max-width: 820px; }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0 } to { transform: none; opacity: 1 } }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .x { cursor: pointer; border: none; background: transparent; font-size: 22px; color: var(--muted); line-height: 1; padding: 2px 6px; border-radius: 6px; }
.modal-head .x:hover { background: #eef1f6; }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: #fafbfd; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: #334155; }
.field .hint { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.field textarea { resize: vertical; min-height: 64px; }
.field.check { flex-direction: row; align-items: center; gap: 9px; }
.field.check input { width: 17px; height: 17px; }

/* ---------- Detail / definition lists ---------- */
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 9px 14px; font-size: 14px; }
.dl dt { color: var(--muted); font-weight: 500; }
.dl dd { margin: 0; font-weight: 500; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin: 22px 0 10px; }

/* invoice positions */
.pos-tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 4px; }
.pos-tbl th, .pos-tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.pos-tbl th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.pos-tbl tfoot td { border: none; padding-top: 6px; }
.pos-total { font-weight: 800; font-size: 16px; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  font-weight: 500; min-width: 220px; max-width: 380px; animation: slidein .2s ease; display: flex; gap: 10px; align-items: center;
}
@keyframes slidein { from { transform: translateX(20px); opacity: 0 } to { transform: none; opacity: 1 } }
.toast.success { background: var(--green-dark); }
.toast.error { background: var(--danger); }
.toast .tic { font-size: 16px; }

/* ---------- misc ---------- */
.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill-tabs { display: inline-flex; background: #eef1f6; border-radius: 10px; padding: 3px; gap: 2px; }
.pill-tabs button { border: none; background: transparent; padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; cursor: pointer; color: var(--muted); }
.pill-tabs button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.filter-input { border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 14px; min-width: 220px; }
.filter-input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.note-box { background: var(--warn-soft); border: 1px solid #f5e0b8; color: #7a4b00; padding: 12px 14px; border-radius: 10px; font-size: 13.5px; }
.note-box.ok { background: var(--green-soft); border-color: #b9e6d8; color: var(--green-dark); }
.note-box.info { background: var(--blue-soft); border-color: #c7d8fb; color: #1e40af; }
.link { color: var(--green-dark); font-weight: 600; text-decoration: none; cursor: pointer; }
.link:hover { text-decoration: underline; }
.soh-bar { height: 7px; background: #eef1f6; border-radius: 99px; overflow: hidden; width: 70px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.soh-bar > span { display: block; height: 100%; border-radius: 99px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #14233b 0%, #0c1726 100%); padding: 24px; }
.login-card { background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.35); width: 100%; max-width: 380px; padding: 32px 30px; }
.login-card .brand-logo { font-size: 34px; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 14px; background: var(--green-soft); margin: 0 auto 14px; }
.login-card h1 { text-align: center; font-size: 21px; margin: 0 0 2px; letter-spacing: .12em; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; }
.login-err { background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c9c5; border-radius: 9px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 14px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; border-top: 1px solid var(--line); padding-top: 14px; }

/* ---------- Sidebar-Benutzer ---------- */
.sidebar-user { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user .su-name { color: #fff; font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.sidebar-user .su-role { color: #8fa2bb; font-size: 11.5px; margin: 2px 0 10px; }
.sidebar-user .su-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.btn-logout { width: 100%; justify-content: center; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); color: #cdd7e6; }
.btn-logout:hover { background: rgba(255,255,255,.12); }

/* ---------- Auswahl-Liste (Tests für Rechnung) ---------- */
.pick-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.pick-row { display: flex; align-items: center; gap: 11px; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick-row:last-child { border-bottom: none; }
.pick-row:hover { background: #fafbfd; }
.pick-row input { width: 17px; height: 17px; }
.logo-prev { max-height: 60px; max-width: 200px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }

@media (max-width: 820px) {
  .sidebar { width: 70px; flex-basis: 70px; }
  .brand-name, .brand-sub, .nav a span:not(.nico):not(.badge), .sidebar-foot { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dt { margin-top: 8px; }
}
