:root {
  --accent: #1f4e8c;
  --accent-dark: #163a6a;
  --accent-soft: #e8f0fa;
  --bg: #f3f5f8;
  --card: #fff;
  --text: #1c2430;
  --muted: #6a7585;
  --line: #dde2ea;
  --ok: #1d8a4b;
  --warn: #c77700;
  --bad: #c62828;
  --radius: 10px;
  --on-accent: #fff;
  --sidebar: #14243b; --sb-text: #cdd6e4; --sb-strong: #fff; --sb-muted: #8fa1bd; --sb-sep: #6f83a3; --sb-hover: rgba(255,255,255,.07); --sb-btn: rgba(255,255,255,.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.monteur { --accent: var(--m-accent, #c2610c); --accent-dark: var(--m-accent-dark, #9a4d09); --accent-soft: var(--m-accent-soft, #fdf0e3); --on-accent: var(--m-on-accent, #fff); }
* { box-sizing: border-box; }
html { margin: 0; height: 100%; }
body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }

/* Layout (Büro) */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--sidebar); color: var(--sb-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.sidebar .brand { padding: 18px 18px 12px; color: var(--sb-strong); font-weight: 700; font-size: 1.05rem; }
.sidebar .brand small { display: block; font-weight: 400; color: var(--sb-muted); font-size: .75rem; margin-top: 2px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 6px 8px; }
.sidebar nav a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; color: inherit; text-decoration: none; border-radius: 8px; margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--sb-hover); }
.sidebar nav a.active { background: var(--accent); color: var(--on-accent); }
.sidebar nav .sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--sb-sep); padding: 14px 12px 4px; }
.sidebar .user { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; }
.sidebar .user button { margin-top: 6px; }
main { flex: 1; min-width: 0; padding: 22px 26px 60px; max-width: 1400px; }
.topbar { display: none; }

@media (max-width: 860px) {
  #app { display: block; }
  .sidebar { position: fixed; z-index: 30; left: -250px; transition: left .2s; width: 240px; }
  .sidebar.open { left: 0; box-shadow: 0 0 30px rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--sidebar); color: var(--sb-strong); padding: 10px 14px; position: sticky; top: 0; z-index: 20; }
  main { padding: 16px 14px 60px; }
}

/* Karten, Tabellen */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 1.55rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.bad .v { color: var(--bad); } .stat.warn .v { color: var(--warn); }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Formulare */
label.f { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 10px; }
label.f > span { display: block; margin-bottom: 3px; }
input, select, textarea { font: inherit; color: inherit; width: 100%; padding: 8px 10px; border: 1px solid #c5ccd8; border-radius: 8px; background: #fff; min-height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: auto; min-height: 0; }
input:disabled, select:disabled, textarea:disabled { background: #f1f3f6; color: #444; }
textarea { min-height: 70px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.form-grid .span2 { grid-column: span 2; } .form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid .span2 { grid-column: span 1; } }
.check { display: flex; align-items: center; gap: 8px; font-size: .95rem; color: var(--text); }

/* Buttons */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; min-height: 38px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: #f1f4f8; }
button.primary, .btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.danger { color: var(--bad); border-color: #e8b9b9; }
button.danger:hover { background: #fdeeee; }
button.small { padding: 4px 9px; min-height: 30px; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: transparent; border-color: transparent; }
.sidebar button { background: var(--sb-btn); border-color: transparent; color: var(--sb-strong); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #e7ebf1; color: #435064; white-space: nowrap; }
.badge.ok { background: #dff3e8; color: #14693a; } .badge.warn { background: #fff0d6; color: #8a5300; }
.badge.bad { background: #fde3e3; color: #a11c1c; } .badge.info { background: #dfeafb; color: #1b4a8e; }

/* Modal & Toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,40,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; align-items: center; }
.modal .body { padding: 16px 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #223; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 340px; }
.toast.err { background: var(--bad); } .toast.ok { background: var(--ok); }

/* Dokument-Editor */
.items-edit { width: 100%; }
.items-edit .it { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #fcfdfe; }
.items-edit .it.heading { background: var(--accent-soft); }
.items-edit .line { display: grid; grid-template-columns: 34px 1fr 80px 70px 100px 70px 100px auto; gap: 8px; align-items: start; }
.items-edit .line.h { grid-template-columns: 34px 1fr auto; }
.items-edit .pos { color: var(--muted); padding-top: 9px; text-align: center; }
.items-edit .total { padding-top: 9px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.items-edit textarea { min-height: 44px; margin-top: 6px; }
.items-edit .lbl { display: none; font-size: .7rem; color: var(--muted); }
@media (max-width: 1000px) {
  .items-edit .line { grid-template-columns: 1fr 1fr 1fr; }
  .items-edit .line > .title { grid-column: 1 / -1; }
  .items-edit .pos { display: none; }
  .items-edit .lbl { display: block; }
}
.totals { margin-left: auto; width: 320px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--text); margin-top: 4px; padding-top: 6px; }
.locked-banner { background: #fff6e0; border: 1px solid #f0d58a; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.chain { display: flex; flex-wrap: wrap; gap: 6px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.08); }
.login-box h1 { text-align: center; }
.err-text { color: var(--bad); font-size: .9rem; min-height: 1.2em; margin: 4px 0 8px; }
.offline-bar { background: #fff0d6; color: #7a4a00; text-align: center; padding: 6px; font-size: .85rem; }

@media print { .sidebar, .topbar, button, .btn { display: none !important; } main { padding: 0; } }

/* 2FA / Konto */
.notice{padding:10px 12px;border-radius:8px;margin-bottom:14px;background:#eef3fb;border:1px solid #cfdcf3}
.notice.warn{background:#fff7e6;border-color:#f3d28a}
pre.recovery{font:600 1.05rem/1.7 ui-monospace,Menlo,Consolas,monospace;background:#f4f6fa;border:1px dashed #9aa9c2;border-radius:8px;padding:12px;text-align:center;user-select:all;white-space:pre}
.qr svg{max-width:220px;height:auto}
.modal h3{margin:0 0 8px;font-size:1rem}

/* Erscheinungsbild / Logo */
.brand-logo { display: block; background: #fff; border-radius: 8px; padding: 6px 8px; margin-bottom: 10px; max-width: 100%; }
.brand-logo img { display: block; max-width: 100%; max-height: 56px; margin: 0 auto; }
.login-logo { display: block; max-width: 240px; max-height: 90px; margin: 0 auto 14px; }
.logo-preview { background: repeating-conic-gradient(#e9edf3 0% 25%, #fff 0% 50%) 50% / 16px 16px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: inline-flex; align-items: center; justify-content: center; min-width: 200px; min-height: 80px; }
.logo-preview img { max-width: 320px; max-height: 110px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { padding: 4px 10px 4px 4px; gap: 6px; }
.swatches i { display: inline-block; width: 22px; height: 22px; border-radius: 5px; }
.color-field { display: flex; gap: 6px; align-items: center; }
.color-field input[type=color] { width: 46px; min-width: 46px; padding: 2px; height: 38px; }
.preview-strip { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; min-height: 110px; }
.preview-strip .ps-side { width: 150px; padding: 12px; font-size: .8rem; }
.preview-strip .ps-main { flex: 1; padding: 12px; }

/* Eingangsrechnungen */
.dropzone { border: 2px dashed #b9c4d3; border-radius: 12px; padding: 18px; text-align: center; background: #fff; margin-bottom: 14px; cursor: pointer; display: grid; gap: 4px; justify-items: center; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.inc-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .inc-layout { grid-template-columns: 1fr; } }
.inc-preview iframe { width: 100%; height: 760px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.inc-preview h3 { margin-top: 0; }
.einv { margin-top: 10px; }
.inc-head, .inc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 76px 112px 104px 104px 34px; gap: 6px; align-items: center; }
.inc-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 0 0 4px; }
.inc-head .num, .inc-grid .num { text-align: right; }
.inc-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; display: grid; gap: 6px; background: #fbfcfe; }
.inc-row .gross { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inc-head span:first-child { padding-left: 2px; }
.totals > div { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; }

/* ---- Datenübernahme, GAEB, DATANORM ---- */
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 14px; }
.steps { margin: 6px 0 10px 1.2em; padding: 0; } .steps li { margin: 3px 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat.ok .v { color: var(--ok, #1f7a3d); }
.note-box { background: #eef4fb; border: 1px solid #c9dbef; border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.note-box.bad { background: #fdeeee; border-color: #f0c2c2; color: var(--bad); }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 18px; margin-bottom: 12px; }
.kv > div { display: flex; flex-direction: column; } .kv span { color: var(--muted); font-size: .8rem; }
table.sample td, table.sample th { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; font-size: .85rem; }
.gaeb-prev { max-height: 340px; overflow: auto; }
.items-edit .pos.oz { font-size: .72rem; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kv { grid-template-columns: 1fr; } }
.items-edit.has-oz .line { grid-template-columns: 74px 1fr 80px 70px 100px 70px 100px auto; }
.items-edit.has-oz .line.h { grid-template-columns: 74px 1fr auto; }
@media (max-width: 1000px) { .items-edit.has-oz .line { grid-template-columns: 1fr 1fr 1fr; } }

/* Dateiauswahl (deutsche Beschriftung statt „Choose File“) */
.filepick { display: inline-flex; align-items: center; gap: 10px; max-width: 100%; min-height: 38px; position: relative; }
.filepick > input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }
.filepick-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
