:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8ef;
    --text: #1f2733;
    --text-soft: #5b6675;
    --text-mute: #8b95a5;
    --brand: #1d4ed8;
    --brand-dark: #1e3a8a;
    --brand-soft: #eef2ff;
    --green: #16a34a;
    --amber: #d97706;
    --red: #dc2626;
    --sidebar-w: 236px;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", Roboto, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
h1 { font-size: 1.5rem; font-weight: 650; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 0 0 .75rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.page { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: linear-gradient(180deg, #172554 0%, #1e3a8a 100%);
    color: #cdd7ee;
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column;
}
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top-row {
    height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: flex-end; gap: 1rem;
    padding: 0 1.5rem; position: sticky; top: 0; z-index: 5;
}
.content { padding: 1.5rem; flex: 1; }

/* ---------- Sidebar / Nav ---------- */
.nav-brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1.1rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.08);
}
.nav-logo {
    width: 30px; height: 30px; border-radius: 7px; background: #fff; color: var(--brand-dark);
    display: grid; place-items: center; font-weight: 800; font-size: 1.05rem;
}
.nav-title { font-weight: 700; letter-spacing: .06em; color: #fff; }
.nav-scroll { overflow-y: auto; padding: .5rem 0 2rem; flex: 1; }
.nav-group {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
    color: #7f92c4; padding: 1rem 1.25rem .3rem;
}
.nav-item {
    display: flex; align-items: center; gap: .65rem;
    padding: .5rem 1.25rem; color: #cdd7ee; font-weight: 500;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,.10); color: #fff; border-left-color: #60a5fa; }
.nav-ico { width: 18px; text-align: center; opacity: .85; }

/* ---------- Topbar user ---------- */
.top-user { display: flex; align-items: center; gap: .55rem; font-weight: 600; color: var(--text-soft); }
.top-user-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft);
    color: var(--brand-dark); display: grid; place-items: center; font-size: .78rem; font-weight: 700;
}
.logout-form { margin: 0; }
.logout-btn {
    border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
    padding: .35rem .8rem; border-radius: 8px; cursor: pointer; font-size: .82rem;
}
.logout-btn:hover { background: var(--surface-2); color: var(--red); border-color: #f0c9c9; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 1.1rem 1.25rem; }
.grid { display: grid; gap: 1rem; }
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat { padding: 1.1rem 1.25rem; }
.stat-label { color: var(--text-mute); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.9rem; font-weight: 700; margin-top: .35rem; }
.stat-sub { color: var(--text-soft); font-size: .82rem; margin-top: .15rem; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.input, select.input {
    border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem;
    font-size: .9rem; background: var(--surface); color: var(--text); min-width: 220px;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn {
    border: 1px solid var(--brand); background: var(--brand); color: #fff;
    padding: .5rem .9rem; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: .88rem;
}
.btn:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--surface); color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data thead th {
    text-align: left; background: var(--surface-2); color: var(--text-soft);
    font-weight: 600; padding: .6rem .85rem; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; white-space: nowrap;
}
table.data tbody td { padding: .55rem .85rem; border-bottom: 1px solid var(--border); }
table.data tbody tr:hover { background: var(--brand-soft); }
table.data tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-blue { background: var(--brand-soft); color: var(--brand-dark); }
.badge-gray { background: #eef1f5; color: var(--text-soft); }

/* ---------- Detail / Formular ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem 1rem; }
.form-grid label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; font-weight: 600; color: var(--text-soft); }
.form-grid label.full { grid-column: 1 / -1; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: .55rem 1rem; margin: 0; }
dl.kv dt { color: var(--text-mute); font-size: .82rem; }
dl.kv dd { margin: 0; }
.mini-stats { display: flex; gap: 1.5rem; }
.mini-stats > div { display: flex; flex-direction: column; }
.mini-num { font-size: 1.6rem; font-weight: 700; }
.mini-lbl { color: var(--text-mute); font-size: .8rem; }

/* ---------- Kundenpicker / Positionsformular ---------- */
.picker { margin-top: .5rem; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; max-height: 280px; overflow-y: auto; }
.picker-item { padding: .55rem .75rem; cursor: pointer; border-bottom: 1px solid var(--border); }
.picker-item:last-child { border-bottom: none; }
.picker-item:hover { background: var(--brand-soft); }
.pos-form { display: grid; grid-template-columns: 1.4fr 1.4fr 1.2fr .8fr .8fr auto; gap: .75rem; align-items: end; }
.pos-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .8rem; font-weight: 600; color: var(--text-soft); }
@media (max-width: 1100px) { .pos-form { grid-template-columns: 1fr 1fr; } }

/* ---------- Autovervollständigung ---------- */
.ac { position: relative; width: 100%; }
.ac-list {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(16,24,40,.12); max-height: 300px; overflow-y: auto;
}
.ac-item { padding: .55rem .75rem; cursor: pointer; border-bottom: 1px solid var(--border); font-weight: 400; }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--brand-soft); }
.chosen { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; font-weight: 500; }
.req { color: var(--red); }

.muted { color: var(--text-mute); }
.empty { padding: 2.5rem; text-align: center; color: var(--text-mute); }
.loading { padding: 2.5rem; text-align: center; color: var(--text-mute); }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; display: grid; place-items: center;
    background: linear-gradient(135deg, #172554 0%, #1e3a8a 55%, #2563eb 100%);
    padding: 1rem;
}
.login-card {
    width: 100%; max-width: 380px; background: #fff; border-radius: 14px;
    padding: 2rem; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.5rem; }
.login-logo {
    width: 46px; height: 46px; border-radius: 11px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.4rem;
}
.login-brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: .06em; }
.login-sub { margin: 0; color: var(--text-mute); font-size: .85rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .85rem; color: var(--text-soft); }
.login-form select, .login-form input {
    border: 1px solid var(--border); border-radius: 9px; padding: .65rem .75rem; font-size: .95rem;
}
.login-form select:focus, .login-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.login-btn {
    margin-top: .3rem; background: var(--brand); color: #fff; border: none; border-radius: 9px;
    padding: .7rem; font-size: .95rem; font-weight: 650; cursor: pointer;
}
.login-btn:hover { background: var(--brand-dark); }
.login-error { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; padding: .6rem .8rem; border-radius: 9px; margin-bottom: 1rem; font-size: .85rem; }

/* ---------- Blazor error ---------- */
#blazor-error-ui {
    background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

@media (max-width: 800px) {
    .sidebar { position: fixed; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
    .page.nav-open .sidebar { transform: none; }
}
