:root{
  --bg:#eceef1;
  --panel:#ffffff;
  --ink:#1a1a1a;
  --muted:#666;
  --line:#d9dce1;
  --accent:#1f4e8c;
  --accent-2:#2b6cb0;
  --good:#1d7a46;
  --hint:#0a66c2;
  --radius:8px;
  --shadow:0 2px 10px rgba(0,0,0,.08);
}
*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
  background:var(--bg); color:var(--ink); font-size:14px;
}

/* ---------- Topbar ---------- */
.topbar{
  position:sticky; top:0; z-index:50;
  display:flex; align-items:center; gap:18px;
  background:#fff; border-bottom:1px solid var(--line);
  padding:10px 18px; box-shadow:var(--shadow);
}
.brand{font-weight:800; color:var(--accent); white-space:nowrap}
.tabs{display:flex; gap:4px; flex:1}
.tab{
  border:0; background:transparent; padding:8px 14px; border-radius:6px;
  cursor:pointer; color:var(--muted); font-weight:600; font-size:14px;
}
.tab:hover{background:#f0f2f5; color:var(--ink)}
.tab.active{background:var(--accent); color:#fff}
.topbar-actions{display:flex; gap:8px}

button.btn{
  border:1px solid var(--accent); background:var(--accent); color:#fff;
  padding:8px 14px; border-radius:6px; cursor:pointer; font-weight:600; font-size:13px;
}
button.btn:hover{background:var(--accent-2)}
button.btn.ghost{background:#fff; color:var(--accent)}
button.btn.ghost:hover{background:#eef3fb}
button.btn.good{background:var(--good); border-color:var(--good)}
button.btn.good:hover{filter:brightness(1.07)}
button.btn:disabled{opacity:.5; cursor:not-allowed}
.icon-btn{border:0;background:transparent;font-size:18px;cursor:pointer;color:var(--muted);line-height:1}

/* ---------- Layout ---------- */
main{padding:22px; max-width:1180px; margin:0 auto}
.view-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:14px}
.view-head h1{font-size:20px; margin:0}
.muted{color:var(--muted)}
.lockbadge{background:#fdecea;color:#a3261b;border:1px solid #f3b6ae;padding:3px 9px;border-radius:99px;font-size:12px;font-weight:600}
.draftbadge{background:#eef6ee;color:#1d7a46;border:1px solid #b6dcc0;padding:3px 9px;border-radius:99px;font-size:12px;font-weight:600}

/* ---------- Tables (lists) ---------- */
table.list{width:100%; border-collapse:collapse; background:#fff; border-radius:var(--radius); overflow:hidden; box-shadow:var(--shadow)}
table.list th,table.list td{padding:10px 12px; text-align:left; border-bottom:1px solid var(--line)}
table.list th{background:#f6f8fa; font-size:12px; text-transform:uppercase; letter-spacing:.03em; color:var(--muted)}
table.list tr:last-child td{border-bottom:0}
table.list tr:hover td{background:#fafbfc}
.right{text-align:right}
.center{text-align:center}
.empty-state{background:#fff;border:1px dashed var(--line);border-radius:var(--radius);padding:40px;text-align:center;color:var(--muted)}

/* ---------- Forms ---------- */
.form-grid{display:grid; grid-template-columns:1fr 1fr; gap:12px}
.field{display:flex; flex-direction:column; gap:4px}
.field.full{grid-column:1/-1}
label{font-size:12px; font-weight:600; color:var(--muted)}
input,select,textarea{
  font:inherit; padding:8px 10px; border:1px solid var(--line); border-radius:6px; background:#fff; color:var(--ink);
}
input:focus,select:focus,textarea:focus{outline:2px solid #cfe0f6; border-color:var(--accent-2)}
textarea{resize:vertical; min-height:54px}
.panel{background:#fff; border-radius:var(--radius); box-shadow:var(--shadow); padding:18px}
.panel h2{margin:0 0 12px; font-size:16px}
.row-actions{display:flex; gap:8px; justify-content:flex-end; margin-top:16px}

/* ---------- Modal ---------- */
.modal-backdrop{
  position:fixed; inset:0; background:rgba(20,24,30,.45); display:flex; align-items:flex-start;
  justify-content:center; padding:40px 16px; z-index:100; overflow:auto;
}
.modal{background:#fff; border-radius:10px; width:min(760px,100%); box-shadow:0 20px 60px rgba(0,0,0,.3)}
.modal-head{display:flex; align-items:center; justify-content:space-between; padding:14px 18px; border-bottom:1px solid var(--line)}
.modal-head h2{margin:0; font-size:17px}
.modal-body{padding:18px}

/* customer pick list inside modal */
.pick-list{display:flex; flex-direction:column; gap:8px; max-height:340px; overflow:auto; margin-bottom:14px}
.pick{display:flex; justify-content:space-between; align-items:center; gap:10px; border:1px solid var(--line); border-radius:8px; padding:10px 12px; cursor:pointer}
.pick:hover{border-color:var(--accent-2); background:#f4f8fd}
.pick .who{font-weight:600}
.pick .addr{color:var(--muted); font-size:13px}

/* positions editor */
.pos-edit{width:100%; border-collapse:collapse}
.pos-edit th{font-size:11px; text-transform:uppercase; color:var(--muted); text-align:left; padding:4px 6px}
.pos-edit td{padding:4px 6px; vertical-align:top}
.pos-edit input,.pos-edit select,.pos-edit textarea{width:100%; padding:6px 7px; font-size:13px}
.pos-edit textarea{min-height:46px}
.w-pos{width:46px}.w-art{width:120px}.w-num{width:64px}.w-me{width:78px}.w-s{width:64px}.w-price{width:90px}
.del-row{color:#a3261b;border:0;background:transparent;cursor:pointer;font-size:16px}

/* ---------- Invoice preview (A4) ---------- */
.editor-wrap{display:flex; gap:18px; align-items:flex-start}
.editor-side{position:sticky; top:78px; width:230px; flex:0 0 230px; display:flex; flex-direction:column; gap:10px}
.editor-side .hintbox{background:#fff;border-radius:var(--radius);box-shadow:var(--shadow);padding:14px;font-size:13px;color:var(--muted);line-height:1.5}
.editor-side .hintbox b{color:var(--ink)}
.pages{flex:1; display:flex; flex-direction:column; align-items:center; gap:18px}

.page{
  background:#fff; width:210mm; min-height:297mm; padding:16mm 15mm;
  box-shadow:0 2px 14px rgba(0,0,0,.18); position:relative;
  font-size:10.5px; color:#111; line-height:1.32;
}
.page *{box-sizing:border-box}

/* clickable zones */
.zone{position:relative; border-radius:4px; transition:background .12s, outline-color .12s; cursor:pointer}
body:not(.exporting) .zone{outline:1px dashed transparent; outline-offset:2px}
body:not(.exporting) .zone:hover{background:#eef6ff; outline-color:#9cc2f0}
body:not(.exporting) .zone:hover::after{
  content:"✎ "attr(data-hint); position:absolute; top:-9px; right:0; transform:translateY(-100%);
  background:var(--hint); color:#fff; font-size:10px; padding:2px 7px; border-radius:5px; white-space:nowrap; z-index:5;
}
.placeholder{color:#b3b9c2; font-style:italic}
body.exporting .placeholder{color:#111; font-style:normal}

/* invoice internals */
.logo{font-size:30px; font-weight:800; letter-spacing:.5px; color:#111; font-family:Georgia,"Times New Roman",serif}
.logo .st{color:#111}
.logo .logo-img{height:46px; width:auto; display:block}

/* Logo-Einstellung (Absender) */
.logo-setting{display:flex; gap:18px; align-items:center; flex-wrap:wrap; margin-bottom:14px}
.logo-preview{min-width:200px; min-height:54px; display:flex; align-items:center; padding:8px 12px; border:1px solid #e1e4ea; border-radius:8px; background:#fff}
.logo-preview img{max-height:54px; max-width:260px; width:auto}
.logo-actions label.btn{cursor:pointer}
.hr-top{border:0;border-top:1px solid #bbb; margin:6px 0 14px}
.doc-title{text-align:right; font-size:17px; font-weight:800; margin:4px 0 18px}
.sender-line{font-size:8.5px; color:#222; margin-bottom:26px}

.head-cols{display:flex; justify-content:space-between; gap:20px; align-items:flex-start}
.pay-box{border:1px solid #333; padding:8px 10px; font-size:9.5px; display:flex; gap:12px; align-items:flex-start; min-width:300px}
.pay-box .lbls > div{white-space:nowrap}
.pay-box .qr img,.pay-box .qr canvas{width:74px;height:74px;display:block}
.pay-box .amount{font-weight:700}

.addr-meta{display:flex; justify-content:space-between; gap:24px; margin-top:30px}
.cust-addr{min-width:240px; min-height:64px}
.cust-addr .name{font-weight:600}
.meta-tbl{font-size:10px}
.meta-tbl div{display:flex; gap:6px}
.meta-tbl .k{width:78px; color:#222}
.meta-tbl .v{font-weight:600}
.meta-tbl .v.strong{font-weight:800}

.salut{margin-top:26px}
.intro{margin-top:8px; white-space:pre-line}
.kred{margin-top:14px}

/* items table */
table.items{width:100%; border-collapse:collapse; margin-top:18px; font-size:10px}
table.items thead th{border-bottom:1px solid #111; padding:3px 4px; text-align:left; font-weight:700; vertical-align:bottom}
table.items thead th.r{text-align:right}
table.items thead th.c{text-align:center}
table.items tbody td{padding:6px 4px; vertical-align:top}
table.items tbody tr+tr td{border-top:0}
.it-pos{width:30px}
.it-desc .art{font-weight:400}
.it-desc .bez{color:#111; white-space:pre-line}
.it-qty{width:34px;text-align:right}
.it-me{width:40px}
.it-pe{width:26px;text-align:center}
.it-s{width:26px;text-align:center}
.it-ep{width:74px;text-align:right}
.it-gp{width:80px;text-align:right}
.items-empty td{color:#b3b9c2;font-style:italic;padding:14px 4px}
body.exporting .items-empty{display:none}

/* totals footer */
.totals{margin-top:auto}
.page .foot-anchor{position:absolute; left:15mm; right:15mm; bottom:16mm}
table.tot{width:100%; border-collapse:collapse; font-size:9px; margin-top:24px}
table.tot td{padding:2px 4px}
table.tot .top{border-top:1px solid #111}
table.tot .lbl{color:#222}
table.tot .num{font-weight:600}
table.tot .grand{font-size:13px; font-weight:800; text-align:right}
.vorkasse{font-size:8.5px; margin-top:8px; color:#222}

/* page 2 */
.legal{font-size:9.5px; line-height:1.4}
.legal p{margin:0 0 8px}
.legal .bold{font-weight:700}
.foot2{position:absolute; left:15mm; right:15mm; bottom:16mm; border-top:1px solid #111; padding-top:6px; display:flex; gap:18px; font-size:8px; color:#222}
.foot2 div{flex:1}
.foot2 .lab{color:#555}
.pg-meta{font-size:10px}

@media print{ body{background:#fff} .topbar,.editor-side{display:none} }
.toast{position:fixed; bottom:22px; left:50%; transform:translateX(-50%); background:#1a1a1a; color:#fff; padding:11px 18px; border-radius:8px; box-shadow:var(--shadow); z-index:200; font-size:14px}
