@font-face { font-family: 'Source Sans Pro'; font-weight: 400; font-display: swap; src: url('/static/fonts/source-sans-pro-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Source Sans Pro'; font-weight: 600; font-display: swap; src: url('/static/fonts/source-sans-pro-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Source Sans Pro'; font-weight: 700; font-display: swap; src: url('/static/fonts/source-sans-pro-latin-700-normal.woff2') format('woff2'); }

:root {
  /* Farben aus dem AraERP-Logo: Blau #014D9C, Schiefergrau #535D63, Flügelgrau #808B90 */
  --blue: #014D9C;
  --blue-dark: #003B78;
  --blue-soft: #E8EFF8;
  --slate: #535D63;
  --slate-light: #808B90;
  --text: #4A5358;
  --head: #232B31;
  --grey: #6B757A;
  --line: #DDE1E1;
  --bg: #F5F7F7;
  --white: #FFFFFF;
  --ok: #2E7D32;
  --ok-soft: #E8F5E9;
  --warn: #8A6100;
  --warn-soft: #FFF6DB;
  --err: #B3261E;
  --err-soft: #FDECEA;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 6px rgba(0,0,0,.04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Source Sans Pro', 'Segoe UI', Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--head); margin: 0 0 .6em; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 600; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
[x-cloak] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #fff; color: var(--text); padding: 14px 0 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--line); }
.sidebar .brand { display: block; padding: 0 16px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.sidebar .brand img { display: block; width: 100%; max-width: 188px; height: auto; }
.sidebar nav a { display: block; padding: 4px 20px 4px 24px; font-size: .93rem; line-height: 1.35; color: var(--slate); border-left: 3px solid transparent; }
.sidebar nav a:hover { background: var(--blue-soft); text-decoration: none; color: var(--blue-dark); }
.sidebar nav a.active { border-left-color: var(--blue); color: var(--blue); background: var(--blue-soft); font-weight: 600; }
.sidebar .group { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--blue); background: #F2F6FB; border-top: 1px solid var(--line); padding: 6px 20px 5px; margin-top: 10px; margin-bottom: 3px; }
.sidebar .group:first-of-type { margin-top: 6px; }
main { padding: 24px 32px 60px; min-width: 0; }

.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.sub { color: var(--grey); font-size: .9rem; }

/* ---------- Karten ---------- */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card > h2:first-child { margin-bottom: 14px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  main { padding: 16px; }
}
.stat { display: block; color: inherit; }
.stat:hover { text-decoration: none; border-color: var(--blue); }
.stat .n { font-size: 1.8rem; font-weight: 700; color: var(--head); }

/* ---------- Formulare ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px 14px; }
.f { display: flex; flex-direction: column; gap: 3px; grid-column: span 6; min-width: 0; }
.f.s2 { grid-column: span 2; } .f.s3 { grid-column: span 3; } .f.s4 { grid-column: span 4; }
.f.s8 { grid-column: span 8; } .f.s9 { grid-column: span 9; } .f.s12 { grid-column: span 12; }
@media (max-width: 800px) { .f, .f.s2, .f.s3, .f.s4, .f.s8, .f.s9 { grid-column: span 12; } }
label, .label { font-size: .8rem; font-weight: 600; color: var(--grey); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input:not([type]), select, textarea {
  font: inherit; color: var(--head); background: #fff;
  border: 1px solid #C8CDCD; border-radius: 4px; padding: 6px 9px; width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
input[readonly], textarea[readonly], select:disabled, input:disabled, textarea:disabled { background: #F2F4F4; color: var(--text); }
.check { display: flex; align-items: center; gap: 7px; font-size: .95rem; color: var(--head); font-weight: 400; }
.check input { width: 16px; height: 16px; accent-color: var(--blue); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: .92rem;
  padding: 7px 14px; border-radius: 4px; border: 1px solid #C8CDCD; background: #fff; color: var(--head);
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--blue); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.small { padding: 3px 9px; font-size: .82rem; }
.btn.icon { padding: 3px 7px; font-size: .85rem; line-height: 1; }
.btn:disabled { opacity: .5; cursor: default; }
form.inline { display: inline; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--grey); font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--blue-soft); }
table.list tr.inactive td { color: #A3A8A8; }
.num, td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* Spaltenköpfe von Zahlenspalten rechtsbündig (sonst gewinnt "table.list th { text-align: left }") */
table.list th.num, table.items th.num { text-align: right; }
table.list th.c { text-align: center; }
.muted { color: var(--grey); }
.empty { text-align: center; color: var(--grey); padding: 28px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: #EEF0F0; color: var(--text); white-space: nowrap; }
.badge.open { background: var(--blue-soft); color: var(--blue-dark); }
.badge.sent { background: #EDE7F6; color: #4527A0; }
.badge.accepted, .badge.paid, .badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.rejected { background: var(--err-soft); color: var(--err); }
.badge.transferred { background: #EEF0F0; color: var(--grey); }
.badge.goods { background: #E3F2FD; color: #0D47A1; }
.badge.service { background: #F3E5F5; color: #6A1B9A; }
.badge.lock { background: var(--head); color: #fff; }

/* ---------- Meldungen ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #B7DDB9; color: var(--ok); }
.flash.warn { background: var(--warn-soft); border-color: #F0D98A; color: var(--warn); }
.flash.err { background: var(--err-soft); border-color: #F2B8B5; color: var(--err); }

/* ---------- Filterleiste ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { max-width: 320px; }
.filters select { width: auto; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 7px 14px; color: var(--text); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--head); border-bottom-color: var(--blue); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--head); }

/* ---------- Ansprechpartner ---------- */
.contact-row { display: grid; grid-template-columns: 90px 1fr 1fr 1fr 1fr 1fr 1fr auto auto; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.contact-row .f { grid-column: auto; }
.contact-row.no-position { grid-template-columns: 90px 1fr 1fr 1fr 1fr 1fr auto auto; }
@media (max-width: 1100px) { .contact-row, .contact-row.no-position { grid-template-columns: 1fr 1fr; } }

/* ---------- Belegeditor ---------- */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 18px; align-items: start; }
.doc-side { position: sticky; top: 16px; }
/* Unter 1700 px braucht die Positionstabelle die volle Breite: Seitenleiste wandert als Kartenreihe nach unten */
@media (max-width: 1700px) {
  .doc-layout { grid-template-columns: 1fr; }
  .doc-side { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; align-items: start; }
  .doc-side .card { margin-bottom: 0; }
}
.items-summary { display: flex; gap: 22px; flex-wrap: wrap; justify-content: flex-end; margin-top: 10px; font-size: .92rem; }
.items-summary b { color: var(--head); font-variant-numeric: tabular-nums; }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin-top: 2px; background: #fff; border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 320px; overflow-y: auto; }
.combo-list div { padding: 6px 10px; cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.combo-list div.hl, .combo-list div:hover { background: var(--blue-soft); }
.combo-list .meta { color: var(--grey); font-size: .82rem; margin-left: auto; white-space: nowrap; }

table.items { width: 100%; border-collapse: collapse; }
table.items th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--grey); font-weight: 600; padding: 6px 4px; border-bottom: 2px solid var(--line); text-align: left; white-space: nowrap; }
table.items td { padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.items input, table.items textarea, table.items select { padding: 4px 6px; font-size: .9rem; }
table.items textarea { min-height: 32px; }
table.items { table-layout: fixed; min-width: 900px; }
table.items .w-pos { width: 36px; color: var(--grey); padding-top: 10px; }
table.items .w-qty { width: 72px; }
table.items .w-unit { width: 62px; }
table.items .w-price { width: 92px; }
table.items .w-disc { width: 58px; }
table.items .w-vat { width: 72px; }
table.items .w-sum { width: 100px; padding-top: 10px; }
table.items .w-margin { width: 100px; padding-top: 10px; }
table.items .w-act { width: 64px; padding-top: 4px; }
table.items .w-act .btn { margin: 0 0 3px; }
.name-line { display: flex; gap: 6px; }
.name-line .nr { width: 92px; flex: none; font-size: .82rem; color: var(--grey); }
table.items tr.textrow td { background: #FAFBFB; }
table.items tr.drag-over td { border-top: 2px solid var(--blue); }
table.items .typebadge { font-size: .7rem; }
.neg { color: var(--err); }
.pos-ok { color: var(--ok); }
.add-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.add-bar .combo { flex: 1; min-width: 260px; }

.totals { width: 100%; border-collapse: collapse; }
.totals td { padding: 4px 0; }
.totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals tr.sum td { border-top: 2px solid var(--head); font-weight: 700; color: var(--head); padding-top: 7px; }
.calc { background: #FBFCFC; border-left: 4px solid var(--blue); }
.calc .big { font-size: 1.5rem; font-weight: 700; color: var(--head); }
.marginbar { height: 8px; background: #EEF0F0; border-radius: 4px; overflow: hidden; margin: 6px 0 10px; }
.marginbar span { display: block; height: 100%; background: var(--blue); }
.related a { display: block; }
.savestate { font-size: .85rem; color: var(--grey); }
.savestate.dirty { color: var(--warn); font-weight: 600; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--blue-soft), #F5F7F8 60%); }
.login { width: 360px; background: #fff; border-radius: 8px; padding: 30px; box-shadow: 0 10px 40px rgba(1,77,156,.12); border-top: 4px solid var(--blue); }
.login .login-logo { margin: 0 0 8px; text-align: center; }
.login .login-logo img { width: 240px; max-width: 100%; height: auto; }
.login h1 span { color: var(--blue); }
#claude h3 { margin: 20px 0 6px; font-size: 15px; }
/* OAuth-Freigabe (auch auf dem Handy) */
.login.consent { width: min(420px, calc(100vw - 32px)); }
.consent h2 { margin: 6px 0 10px; font-size: 20px; }
.consent-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0 14px; }
.consent-facts dt { color: var(--muted, #737878); }
.consent-facts dd { margin: 0; overflow-wrap: anywhere; }
.consent-write { display: flex; gap: 8px; align-items: flex-start; margin: 4px 0 10px; line-height: 1.4; }
.consent-write input { margin-top: 3px; flex: none; }
.token-scope { display: inline; }
.consent-actions { display: flex; gap: 10px; margin-top: 16px; }
.consent-actions .btn { flex: 1; justify-content: center; }

/* Belegbezeichnung */
table.list td.doc-title-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h1 .doc-title { display: block; font-size: 1rem; font-weight: 400; color: var(--grey); margin-top: 2px; }
table.list td.nowrap { white-space: nowrap; }

/* Preiskalkulation Artikel */
table.calc-table { width: 100%; border-collapse: collapse; }
table.calc-table td, table.calc-table th { padding: 4px 6px; vertical-align: middle; }
table.calc-table td:first-child { width: 46%; }
table.calc-table td:nth-child(2) { width: 34%; white-space: nowrap; }
table.calc-table td:nth-child(2) input { width: calc(100% - 22px); text-align: right; }
table.calc-table td:nth-child(2) select { width: 100%; }
table.calc-table td:nth-child(3) { color: var(--grey); font-size: .9rem; }
table.calc-table .unit { display: inline-block; width: 18px; margin-left: 4px; color: var(--grey); }
table.calc-table tr.grp th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--grey); font-weight: 600; padding-top: 12px; border-bottom: 1px solid var(--line); }
table.calc-table tr.sum td { font-weight: 600; color: var(--head); border-top: 1px solid var(--line); }
table.calc-table input[readonly] { background: #F3F5F5; }
table.calc-table .hint { color: var(--grey); font-weight: 400; font-size: .85rem; }
.calc-result { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.calc-result .big { font-size: 1.25rem; }
.is-hidden { display: none !important; }
table.calc-table tr.sum td.hint, table.calc-table td .hint { font-weight: 400; color: var(--grey); }
@media (max-width: 600px) {
  table.calc-table td:first-child { width: auto; }
  table.calc-table td:nth-child(2) { width: 132px; min-width: 132px; }
  table.calc-table td:nth-child(3) { font-size: .8rem; white-space: nowrap; }
  table.calc-table td, table.calc-table th { padding: 4px 3px; }
  .calc-result { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  table.calc-table { table-layout: fixed; }
  table.calc-table col.c-input { width: 118px; }
  table.calc-table col.c-amount { width: 66px; }
  table.calc-table td:nth-child(2) { width: auto; min-width: 0; }
  table.calc-table td:nth-child(3) { overflow: hidden; text-overflow: ellipsis; }
}

/* Kalkulation im Belegeditor */
table.items .pos-calc { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 6px; padding: 6px 8px; background: var(--blue-soft); border-radius: 4px; font-size: .85rem; }
table.items .pos-calc label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-size: .85rem; color: var(--text); }
table.items .pos-calc input { width: 64px; }
table.items .pos-calc select { width: auto; font-size: .82rem; }
.bulk-calc .bc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bulk-calc .bc-val { display: flex; align-items: center; gap: 4px; }
.bulk-calc .bc-val input { width: 100%; }
/* Zahlungskonditionen (Einstellungen) */
table.terms-table td { vertical-align: middle; }
table.terms-table input:not([type=radio]):not([type=checkbox]) { width: 100%; }
table.terms-table td:first-child { min-width: 220px; }
table.terms-table td:nth-child(5) { min-width: 260px; }

/* Titel, Titelsummen, optionale Positionen */
table.items tr.titlerow td { background: var(--blue-soft); border-top: 2px solid var(--blue); }
table.items .title-line { display: flex; gap: 10px; align-items: center; }
table.items .title-input { font-weight: 700; font-size: 1rem; color: var(--head); }
table.items tr.subtotalrow td { background: #F6F8F8; font-weight: 600; color: var(--head); padding-top: 8px; border-bottom: 2px solid var(--line); }
table.items tr.subtotalrow .subtotal-label { text-align: right; }
table.items tr.optrow td:not(.w-act) { color: var(--grey); }
table.items tr.optrow input:not([type=checkbox]), table.items tr.optrow textarea { color: var(--grey); font-style: italic; }
table.items .opt-check { display: inline-flex; align-items: center; gap: 3px; margin: 0; font-size: .8rem; color: var(--grey); white-space: nowrap; }
.title-summary { margin: 12px 0 0 auto; max-width: 420px; }
.title-summary h3 { margin: 0 0 4px; font-size: .9rem; }
.title-summary tr.optrow td { color: var(--grey); font-style: italic; }

/* Statistik Kunde: Balkendiagramm Umsatz / DB */
.sales-chart { display: grid; grid-template-columns: minmax(0, 3fr) minmax(220px, 2fr); gap: 8px 28px; align-items: start; }
.sales-chart .chart-legend { grid-column: 1 / -1; display: flex; gap: 18px; font-size: .85rem; color: var(--text); }
.sales-chart .chart-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sales-chart .sw-net, .sales-chart .bar-net { background: var(--blue); fill: var(--blue); }
.sales-chart .sw-db, .sales-chart .bar-db { background: var(--slate-light); fill: var(--slate-light); }
.sales-chart svg { width: 100%; height: auto; display: block; }
.sales-chart .grid { stroke: #E6E9E9; stroke-width: 1; }
.sales-chart .axis { stroke: #A3A8A8; stroke-width: 1; }
.sales-chart .tick { font-size: 11px; fill: var(--grey); font-family: inherit; }
.sales-chart .tick.year { fill: var(--text); font-weight: 600; }
.sales-chart .hit { fill: transparent; }
.sales-chart .grp:hover .hit { fill: var(--blue-soft); }
.sales-chart .chart-table { font-size: .9rem; }
.sales-chart > .sub { grid-column: 1 / -1; }
@media (max-width: 800px) { .sales-chart { grid-template-columns: minmax(0, 1fr); } }
/* Kundenimport */
.badge.err { background: #FDECEA; color: #B42318; }
table.list tr.err-row td { background: #FFF6F5; }
table.import-map td { vertical-align: middle; }
table.import-map select { min-width: 260px; }
.import-summary { display: flex; flex-wrap: wrap; gap: 8px; }

/* Kopfzeile der Erfassungsformulare: Aktionen oben, beim Scrollen sichtbar */
.page-head.form-head { position: sticky; top: 0; z-index: 20; background: var(--bg); margin: -10px -32px 18px; padding: 10px 32px 12px; border-bottom: 1px solid var(--line); }
.page-head .inline-form { display: inline; margin: 0; }
.page-head.form-head h1 { margin-right: 12px; }
@media (max-width: 800px) { .page-head.form-head { margin: -8px -16px 14px; padding: 8px 16px; } }

table.items .group-select { width: auto; max-width: 180px; font-size: .8rem; padding: 1px 4px; }

/* Rollen und Rechte */
fieldset.plain-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
table.perm-matrix td.c, table.perm-matrix th.c { text-align: center; width: 90px; }
table.perm-matrix td { vertical-align: middle; }
table.roles-table th.perm-col { white-space: normal; font-size: .7rem; max-width: 110px; }
table.roles-table td.perm-col { white-space: nowrap; }
.perm { font-size: .78rem; padding: 1px 7px; border-radius: 10px; }
.perm-write { background: var(--blue-soft); color: var(--blue-dark); font-weight: 600; }
.perm-read { background: #EEF0F0; color: var(--text); }
.perm-none { color: var(--slate-light); }
/* Kopfzeile einzeilig halten: Titel kürzen statt Buttons umbrechen */
@media (min-width: 1000px) {
  .page-head.form-head { flex-wrap: nowrap; gap: 8px; }
  .page-head.form-head h1 { font-size: 1.45rem; margin-right: 6px; }
  .page-head.form-head > * { flex-shrink: 0; }
  .page-head.form-head h1 { flex-shrink: 1; min-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-head.form-head h1 .doc-title { overflow: hidden; text-overflow: ellipsis; }
  .page-head.form-head .savestate { flex-shrink: 1; min-width: 0; overflow: hidden; white-space: nowrap; }
}

/* Belegeditor: Kopfzeile und Reiter gemeinsam fixiert */
.doc-top { position: sticky; top: 0; z-index: 20; background: var(--bg); margin: -10px -32px 16px; padding: 10px 32px 0; border-bottom: 1px solid var(--line); }
.doc-top .page-head.form-head { position: static; margin: 0 0 8px; padding: 0; border: 0; background: none; }
.doc-tabs { display: flex; gap: 2px; margin-bottom: -1px; overflow-x: auto; }
.doc-tabs button { background: none; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; padding: 8px 16px 9px; font: inherit; font-weight: 600; color: var(--slate); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.doc-tabs button:hover { color: var(--blue-dark); background: var(--blue-soft); }
.doc-tabs button.active { background: #fff; border-color: var(--line); color: var(--blue); box-shadow: inset 0 3px 0 var(--blue); }
.doc-tabs .tab-count { background: var(--blue-soft); color: var(--blue-dark); border-radius: 10px; padding: 0 7px; font-size: .78rem; }
.doc-tabs .tab-note { font-weight: 400; font-size: .82rem; color: var(--grey); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.doc-tabs .tab-note.warn { color: var(--err); }
@media (max-width: 800px) { .doc-top { margin: -8px -16px 14px; padding: 8px 16px 0; } }

/* Lieferstand je Position (Auftrag) */
table.items .dlv { font-size: .72rem; line-height: 1.2; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
.dlv-open, .dlv-new { color: var(--grey); }
.dlv-partial { color: var(--warn); font-weight: 600; }
.dlv-full { color: var(--ok); font-weight: 600; }
.dlv-over { color: var(--err); font-weight: 600; }
.doc-tabs .tab-note.dlv-partial { color: var(--warn); }
.doc-tabs .tab-note.dlv-full { color: var(--ok); }

h1 .doc-type { display: block; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--grey); margin-bottom: 1px; }
.doc-tabs .tab-note.dlv-over { color: var(--err); }

/* Dialog (z. B. Positionen aus Beleg) */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(35, 43, 49, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; }
.modal { width: min(980px, 100%); max-height: 88vh; overflow: auto; margin: 0; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }

/* Lizenzen */
.license-box { background: #F7F9FC; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.license-box .license-opts { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 6px; }
.license-box .license-opts label { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
table.license-table td { vertical-align: top; }
table.license-table select, table.license-table input { width: 100%; }
table.license-table tr.license-group td { background: #F2F6FB; border-top: 2px solid var(--line); font-weight: 700; color: var(--head, #1D1D1B); }
table.license-table tr.license-subtotal td { font-weight: 700; border-top: 1px solid var(--line); }
table.license-table td.license-sum { white-space: nowrap; vertical-align: middle; }
table.license-table tr.license-subtotal td div, table.license-table tfoot td div { white-space: nowrap; }
table.billing-table tr.billing-customer td { background: #F2F6FB; border-top: 2px solid var(--line); }
table.license-table { table-layout: auto; min-width: 980px; }
table.license-table td:nth-child(1) { min-width: 260px; }
table.license-table tbody tr:not(.license-group):not(.license-subtotal) td:nth-child(8) { min-width: 170px; }
table.license-table td:nth-child(2), table.license-table td:nth-child(3), table.license-table td:nth-child(5), table.license-table td:nth-child(6), table.license-table td:nth-child(7) { width: 1%; }

/* Hersteller: Ansprechpartner mit Bild, Funktion, LinkedIn */
.contact-row .contact-extra { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; }
.contact-row .contact-extra .f { min-width: 200px; }
.contact-photo { width: 56px; height: 56px; border-radius: 50%; overflow: hidden; background: var(--blue-soft); color: var(--blue-dark); display: grid; place-items: center; font-weight: 700; flex: 0 0 auto; cursor: pointer; border: 1px solid var(--line); }
.contact-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vendor-group + .vendor-group { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.vendor-group h3 { margin: 0 0 8px; }
.vendor-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.vendor-card { display: flex; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; font-size: .9rem; }
.vendor-card .contact-photo { cursor: default; }
.is-hidden { display: none !important; }

/* Benutzermenü: letztes Element der Seitenkopfzeile (per Skript eingehängt), durch einen Strich von den
   Seiten-Buttons getrennt. Ohne Kopfzeile bleibt es rechtsbündig über dem Inhalt. */
.user-menu-wrap { display: flex; justify-content: flex-end; margin: -12px 0 8px; }
.user-menu-wrap.in-head { margin: 0 0 0 auto; padding-left: 12px; border-left: 1px solid var(--line); align-self: stretch; align-items: center; flex-shrink: 0; }
@media (max-width: 800px) { .user-menu .user-name { display: none; } }
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 2px 10px 2px 2px; border-radius: 999px; color: var(--head); font-weight: 600; font-size: .9rem; max-width: 220px; }
.user-menu .user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover, .user-menu[open] summary { background: var(--blue-soft); }
.user-menu .avatar { width: 30px; height: 30px; border-radius: 50%; overflow: hidden; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 700; flex: 0 0 auto; }
.user-menu .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px 0; }
.user-dropdown .user-head { padding: 8px 14px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; gap: 2px; }
.user-dropdown a, .user-dropdown button { display: block; width: 100%; text-align: left; padding: 8px 14px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-decoration: none; }
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--blue-soft); color: var(--blue-dark); }
.user-dropdown form { margin: 0; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.photo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.contact-photo.large { width: 72px; height: 72px; font-size: 1.2rem; }

/* Mitarbeiter: Rollenauswahl, Provisionen */
.role-checks { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 6px 0; }
.period-nav { display: flex; align-items: center; gap: 6px; }
.period-nav input[type=month] { width: auto; }
table.list tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.rates-table input { width: 100%; min-width: 70px; }
.rates-table td { vertical-align: middle; }

/* Logo in den Einstellungen */
.logo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-preview { min-width: 220px; height: 64px; padding: 6px 10px; border: 1px dashed var(--line); border-radius: 6px; display: flex; align-items: center; justify-content: flex-end; background: #fff; }
.logo-preview img { max-height: 52px; max-width: 260px; object-fit: contain; display: block; }

/* Zugang für Claude (MCP) im Profil */
.token-new { background: #EEF7FB; border: 1px solid #0091C1; border-radius: 6px; padding: 12px 14px; margin: 0 0 14px; }
.token-input { width: 100%; font-family: Consolas, monospace; font-size: 13px; margin-top: 6px; }
.token-create { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.token-create input { flex: 1 1 260px; }
.token-create .check { flex: none; white-space: nowrap; align-self: center; }
#claude code { white-space: nowrap; }
/* Profil: Karten so breit wie nötig für die Zugangsliste, aber Fließtext gut lesbar */
.profile-card { max-width: 1080px; }
.profile-card > p.sub, .profile-card > h3 + p.sub { max-width: 820px; }
.token-table td.nowrap, .token-table th { white-space: nowrap; }
.token-table td.actions > * { display: inline-block; margin: 2px 0 2px 4px; }
.token-table td.actions { text-align: right; min-width: 120px; }
/* Schmalere Bildschirme: „Angelegt“ und „Aufrufe“ ausblenden, damit Status und Schalter sichtbar bleiben */
@media (max-width: 1200px) { .token-table .opt-col { display: none; } }
/* Handy: jeder Zugang als Block statt Tabellenzeile */
@media (max-width: 700px) {
  .token-table thead { display: none; }
  .token-table, .token-table tbody, .token-table tr, .token-table td { display: block; width: auto; }
  .token-table tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  table.list.token-table td { border: 0; padding: 2px 0; }
  .token-table td.token-name { font-weight: 600; }
  .token-table td[data-label]::before { content: attr(data-label) ': '; color: var(--grey); }
  .token-table td.actions { text-align: left; min-width: 0; padding-top: 6px; }
  .token-table td.actions > * { margin: 2px 6px 2px 0; }
}

/* ---------- Tickets ---------- */
.ticket-card { max-width: 1080px; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; max-width: 1400px; }
.ticket-side { position: sticky; top: 16px; }
@media (max-width: 1100px) { .ticket-layout { grid-template-columns: minmax(0, 1fr); } .ticket-side { position: static; } }
.ticket-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--head); }
.ticket-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.ticket-tabs { margin: -6px 0 14px; }
.ticket-facts { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px 10px; margin: 0; }
.ticket-facts dt { font-size: .8rem; font-weight: 600; color: var(--grey); padding-top: 2px; }
.ticket-facts dd { margin: 0; overflow-wrap: anywhere; }
.ticket-edit > summary { cursor: pointer; list-style: none; }
.ticket-edit > summary::-webkit-details-marker { display: none; }
.ticket-edit > summary h2 { display: inline; margin: 0; }
.ticket-edit > summary h2::after { content: ' ▸'; color: var(--grey); font-weight: 400; }
.ticket-edit[open] > summary h2::after { content: ' ▾'; }
.ticket-edit[open] > summary { margin-bottom: 12px; }
.ticket-history { list-style: none; margin: 0; padding: 0; }
.ticket-history li { border-left: 3px solid var(--line); padding: 8px 0 10px 14px; margin-left: 4px; }
.ticket-history li + li { border-top: 1px solid #EEF0F0; }
.ticket-history .th-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin-bottom: 4px; }
.ticket-history .th-meta { margin-left: auto; }
.ticket-history .ticket-text { font-size: .95rem; }
.ticket-history li.th-work { border-left-color: var(--blue); }
.ticket-history li.th-work .th-badge { background: var(--blue-soft); color: var(--blue-dark); }
.ticket-history li.th-note { border-left-color: var(--warn); background: var(--warn-soft); }
.ticket-history li.th-note .th-badge { background: #fff; color: var(--warn); }
.ticket-history li.th-forward { border-left-color: #6A1B9A; }
.ticket-history li.th-forward .th-badge { background: #F3E5F5; color: #6A1B9A; }
.ticket-history li.th-status .th-badge, .ticket-history li.th-change .th-badge, .ticket-history li.th-created .th-badge { background: #EEF0F0; color: var(--grey); }
.ticket-history li.th-status, .ticket-history li.th-change, .ticket-history li.th-created { font-size: .92rem; }
.th-edit { margin-top: 6px; }
.th-edit summary { cursor: pointer; font-size: .85rem; color: var(--blue-dark); }
.th-edit form { margin-top: 8px; }
.badge.t-new { background: var(--blue-soft); color: var(--blue-dark); }
.badge.t-in_progress { background: #EDE7F6; color: #4527A0; }
.badge.t-waiting { background: var(--warn-soft); color: var(--warn); }
.badge.t-done { background: var(--ok-soft); color: var(--ok); }
.badge.t-closed { background: #EEF0F0; color: var(--grey); }
.badge.p-low { background: #EEF0F0; color: var(--grey); }
.badge.p-normal { background: #fff; color: var(--text); border: 1px solid var(--line); }
.badge.p-high { background: var(--warn-soft); color: var(--warn); }
.badge.p-urgent { background: var(--err-soft); color: var(--err); }
table.ticket-table td.ticket-assign { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; color: var(--grey); }
@media (max-width: 1200px) { .ticket-table .opt-col { display: none; } }
table.time-report th, table.time-report td { padding-left: 6px; padding-right: 6px; }
table.time-report td.num, table.time-report th.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.time-report td.muted { color: #B8BFC2; }
table.time-report tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
table.ticket-table td.ticket-assignee { min-width: 110px; }
table.ticket-table .ticket-take { margin-top: 4px; }
table.ticket-table .ticket-take .btn { white-space: nowrap; }
