:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --text: #1d2733;
    --muted: #6b7785;
    --border: #dde3ea;
    --primary: #1f4e79;
    --primary-text: #ffffff;
    --danger: #b3261e;
    --success: #1b7f4b;
    --warn: #b26a00;
    --radius: 8px;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; }
h2:first-child { margin-top: 0; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; color: var(--muted); }
.muted, small { color: var(--muted); }
.center { text-align: center; }
.right { text-align: right; }
.small { font-size: 1rem !important; }
.text-danger { color: var(--danger); }
.hint { display: block; color: var(--muted); font-size: .8rem; margin-top: .2rem; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; flex: none; background: #14283b; color: #cfd8e3; display: flex; flex-direction: column; padding: 1rem 0; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { display: flex; align-items: center; gap: .65rem; color: #fff; font-weight: 700; font-size: 1.1rem; padding: 0 1.2rem 1rem; line-height: 1.15; }
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand img { flex: none; width: auto; max-width: 190px; object-fit: contain; }
.app-version { padding: .4rem 1.2rem; font-size: .7rem; color: #7f93a8; }
.nav-logo-preview { background: #14283b; display: inline-block; padding: .8rem 1.2rem; border-radius: 8px; }
.sidebar .brand small { display: block; font-weight: 400; font-size: .72rem; color: #8fa3b8; margin-top: .15rem; }
.plain-logo { text-align: center; margin-bottom: 1rem; }
.plain-logo img { background: #14283b; border-radius: 18px; padding: 8px; }
.catalog-picker { width: auto; max-width: 100%; }
.sidebar nav { flex: 1; overflow-y: auto; }
.sidebar nav a { display: block; padding: .55rem 1.2rem; color: #cfd8e3; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 #6fb1ea; }
.nav-sep { display: block; padding: 1rem 1.2rem .3rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7f93a8; }
.sidebar-user { padding: .8rem 1.2rem 0; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; }
.sidebar-user a { color: #fff; }
.sidebar-user small { color: #8fa3b8; }
.main { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; max-width: 1300px; }
.menu-toggle { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head h2 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form, form.inline { display: inline; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card.narrow, .narrow { max-width: 560px; }
.card.center { max-width: 520px; margin: 3rem auto; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.cols .wide { grid-column: span 2; }
.cols .side { display: flex; flex-direction: column; }
@media (max-width: 900px) { .cols .wide { grid-column: auto; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.1rem; }
.stat span { display: block; color: var(--muted); font-size: .8rem; }
.stat strong { font-size: 1.35rem; }
.stat-warn strong { color: var(--danger); }

/* Plain-Seiten (Login/Install) */
body.plain { display: flex; justify-content: center; padding: 3rem 1rem; }
.plain-box { width: 100%; max-width: 640px; }
.plain-box .card { padding: 1.6rem; }

/* Buttons */
.btn { display: inline-block; font: inherit; padding: .45rem .9rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; cursor: pointer; }
.btn:hover { background: #eef2f6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: #17405f; }
.btn-danger { color: var(--danger); border-color: #e3b4b1; }
.btn-danger:hover { background: #fdeceb; }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: 0; padding: 0 .3rem; font: inherit; color: var(--primary); cursor: pointer; }
button.link.danger { color: var(--danger); font-size: 1.2rem; line-height: 1; }
.sidebar-user button.link { color: #8fc3f0; padding: .3rem 0 0; }

/* Formulare */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.grid .span2 { grid-column: span 2; }
@media (max-width: 600px) { .grid .span2 { grid-column: auto; } }
.field { margin-bottom: .85rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.field-check label { font-weight: 400; display: flex; gap: .4rem; align-items: center; }
input, select, textarea { font: inherit; color: inherit; width: 100%; padding: .45rem .6rem; border: 1px solid #c4ccd6; border-radius: 6px; background: #fff; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: .1rem; height: 2.3rem; width: 5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc4e8; border-color: var(--primary); }
textarea { resize: vertical; }
.field-error { display: block; color: var(--danger); font-size: .8rem; margin-top: .2rem; }
.check { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1; min-width: 200px; width: auto; }
.filters select { width: auto; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .8rem; }
.inline-form > * { width: auto; }
.inline-form .grow { flex: 1; min-width: 160px; }
.grow { flex: 1; min-width: 0; }
.w-x { width: 2rem; flex: none; }
.w-xs { width: 5.5rem; flex: none; }
.w-sm { width: 8rem; flex: none; }
.row-line { display: flex; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.row-line input, .row-line textarea { width: auto; }
.row-line .grow { width: 0; }
.item-block { margin-bottom: .4rem; }
.item-block.kind-group { border-left: 3px solid var(--primary); padding-left: .6rem; background: #f7fafd; border-radius: 0 6px 6px 0; }
.item-block .row-line { margin-bottom: .2rem; }
.group-details { margin: 0 0 .5rem 0; display: none; }
.sub-item { display: flex; gap: .4rem; margin-bottom: .25rem; align-items: flex-start; }
.group-lines { margin-top: .4rem; font-size: .85rem; }
.group-lines summary { cursor: pointer; color: var(--muted); margin-bottom: .3rem; }
.kind-group.has-subs .own-field { visibility: hidden; }
.kind-group .group-details { display: block; }
.sub-line { display: flex; gap: .3rem; margin-bottom: .25rem; }
.sub-line input { flex: 1; font-size: .85rem; }
.pagebreak-label { display: none; color: var(--muted); text-align: center; border-top: 1px dashed var(--muted); padding-top: .15rem; font-size: .8rem; }
.kind-pagebreak .pagebreak-label { display: block; }
.kind-pagebreak [data-desc], .kind-pagebreak .calc-field, .kind-text .calc-field { display: none; }
.item-block.kind-text { border-left: 3px solid var(--muted); padding-left: .6rem; }
.group-details label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .2rem; }
.group-details textarea { width: 100%; font-size: .85rem; }
.item-details { color: var(--muted); font-size: .85em; margin-top: .25rem; }
.items-head { display: flex; gap: .5rem; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .3rem; }
.line-total { font-variant-numeric: tabular-nums; }
.totals { margin: 1rem 0 1rem auto; max-width: 280px; }
.totals div { display: flex; justify-content: space-between; padding: .2rem 0; }
.totals .grand { border-top: 2px solid var(--primary); margin-top: .3rem; padding-top: .4rem; font-size: 1.1rem; }
.perm-group { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 .8rem; padding: .5rem 1rem .7rem; }
.perm-group legend { font-weight: 600; padding: 0 .4rem; }
.perm-group .check { display: flex; margin: .3rem 0; white-space: normal; }
.logo-preview { max-width: 240px; max-height: 100px; border: 1px dashed var(--border); padding: .4rem; background: #fff; }

/* Tabellen */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover { background: #fafbfd; }
.table tfoot td { border-bottom: 0; }
.table tfoot .grand td { font-weight: 700; border-top: 2px solid var(--primary); }
.table select { width: auto; padding: .2rem .4rem; }
.is-done td { color: var(--muted); }
.is-done td:first-child { text-decoration: line-through; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .45rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list.small { font-size: .85rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: .5rem 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
address { font-style: normal; }
.notes { background: #fff9e6; border: 1px solid #f1e2a8; padding: .6rem .8rem; border-radius: 6px; }
pre.code { text-align: left; background: #f1f3f6; padding: .7rem; border-radius: 6px; overflow: auto; }

/* Badges */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #e8edf3; color: #3b4a5a; vertical-align: middle; }
.badge-active, .badge-sent, .badge-doing { background: #dcecfb; color: #14538a; }
.badge-done, .badge-paid, .badge-accepted { background: #dcf3e6; color: var(--success); }
.badge-paused, .badge-overdue, .badge-declined, .badge-expired { background: #fbe3e1; color: var(--danger); }
.badge-planned, .badge-draft, .badge-todo { background: #eceff3; }
.badge-cancelled, .badge-archived { background: #eceff3; color: #8a95a1; text-decoration: line-through; }

/* Meldungen */
.flash { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: #e6f6ed; border-color: #b6e2c8; color: #135c36; }
.flash-error { background: #fdeceb; border-color: #f0bcb9; color: #8a1b14; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem 1rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Mobil */
@media (max-width: 800px) {
    .sidebar { position: fixed; left: -240px; z-index: 20; transition: left .2s; }
    .sidebar.open { left: 0; }
    .main { padding: 1rem; }
    .menu-toggle { display: block; background: none; border: 1px solid var(--border); border-radius: 6px; font-size: 1.2rem; padding: .2rem .6rem; margin-bottom: 1rem; }
    .item-row { flex-wrap: wrap; }
}
.table .sub-row td { color: var(--muted); font-size: .9em; }
.table .sub-desc { padding-left: 1.6rem; }
.table .group-title td { background: #f7fafd; }
.table .detail-row td { color: var(--muted); font-size: .85em; padding-top: .1rem; padding-bottom: .1rem; border-top: 0; }
.table .detail-row .d-date { display: inline-block; min-width: 5.5rem; }
