:root {
  --bg: #0c0c0d; --panel: #161618; --panel2: #1f1f22; --line: #2a2a2e; --line2: #36363b;
  --text: #f2f2f3; --muted: #9a9aa2; --accent: #f5841f; --accent2: #ff9c42; --accentbg: rgba(245,132,31,.14);
  --pos: #4ade80; --neg: #f87171; --warn: #fbbf24;
  --r: 14px; --r-sm: 9px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.7rem; letter-spacing: -.02em; }
h3 { font-size: 1.05rem; margin-bottom: .8rem; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.t-pos { color: var(--pos); } .t-neg { color: var(--neg); }
.ic { width: 18px; height: 18px; flex-shrink: 0; vertical-align: -3px; }
.ic.xl { width: 56px; height: 56px; color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Layout */
#app { display: flex; min-height: 100vh; }
.side { width: 232px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand img { width: 38px; height: 38px; border-radius: 10px; }
.brand b { display: block; font-size: 1.05rem; } .brand small { color: var(--muted); font-size: .78rem; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--r-sm); color: var(--muted); text-decoration: none; font-weight: 500; }
.side nav a:hover { background: var(--panel2); color: var(--text); }
.side nav a .ns { display: none; }
.side nav a.active { background: var(--accentbg); color: var(--accent2); }
.side-foot { margin-top: auto; padding: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { flex: 1; min-width: 0; padding: 26px clamp(16px, 3vw, 40px) 100px; max-width: 1400px; }
.vhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.vhead h1 small { font-size: .9rem; font-weight: 400; }
.vact, .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row { margin-top: 12px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); padding: 9px 14px; border-radius: var(--r-sm); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #4a4a50; background: #26262a; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.ghost { background: transparent; }
.btn.danger { background: #b4232a; border-color: #b4232a; color: #fff; }
.btn.danger-text { color: var(--neg); }
.btn.sm { padding: 6px 10px; font-size: .86rem; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--panel2); color: var(--text); border-color: var(--line2); }
.grow { flex: 1; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; }
.kpi span { color: var(--muted); font-size: .85rem; display: block; }
.kpi b { font-size: 1.75rem; letter-spacing: -.02em; display: block; margin-top: 4px; }
.kpi small { color: var(--muted); font-size: .78rem; }
.note { display: flex; gap: 12px; align-items: flex-start; background: var(--accentbg); border: 1px solid rgba(245,132,31,.35); padding: 12px 16px; border-radius: var(--r); margin-bottom: 18px; }
.note .ic { color: var(--accent2); margin-top: 2px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); grid-column: 1 / -1; }
.badge { display: inline-block; font-size: .74rem; padding: 2px 8px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line2); color: var(--muted); font-weight: 500; vertical-align: middle; }
.badge.loc { color: #c7d2fe; border-color: #3b3f63; background: #1d1f33; }
.badge.warn { color: var(--warn); border-color: #5c4a14; background: #2a2210; }

/* Tables */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--panel2); }
.tbl tr.sel td { background: var(--accentbg); }
.card:not(.flush) .tbl th, .card:not(.flush) .tbl td { padding-left: 6px; padding-right: 6px; }
ul.mini { list-style: none; margin: 0; padding: 0; }
ul.mini li { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 6px; }
ul.mini li:hover { background: var(--panel2); }
ul.mini li span { flex: 1; }
.legend { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.legend dt { font-weight: 700; color: var(--accent2); } .legend dd { margin: 0; }

/* Toolbar & inputs */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--r-sm); padding: 9px 12px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accentbg); }
.toolbar select { width: auto; }
.search { position: relative; flex: 1; min-width: 200px; }
.search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 36px; }
.search.sm { flex: 0 1 240px; min-width: 150px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.check.inline { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.check small { display: block; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
.form-grid > * { grid-column: span 6; }
.form-grid > .half { grid-column: span 3; } .form-grid > .third { grid-column: span 2; }
.form-sec { grid-column: 1 / -1; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.form-grid .form-sec { margin: 6px 0 -4px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 600; }
.field small { color: var(--muted); font-size: .78rem; }
.field .field { gap: 6px; }
.inp { position: relative; }
.inp.has-suf input { padding-right: 52px; }
.inp .suf { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .85rem; pointer-events: none; }
.inp.sm input { padding: 6px 40px 6px 10px; text-align: right; }
.color-field { display: flex; align-items: center; gap: 10px; }
.color-field input { width: 54px; height: 40px; padding: 3px; cursor: pointer; }
.img-field { display: flex; gap: 14px; align-items: center; }
.img-prev { width: 96px; height: 96px; border-radius: 10px; background: var(--panel2); border: 1px dashed var(--line2); display: grid; place-items: center; overflow: hidden; flex-shrink: 0; color: var(--muted); font-size: .78rem; }
.img-prev img { width: 100%; height: 100%; object-fit: cover; }
.img-ctrl { display: flex; flex-direction: column; gap: 8px; flex: 1; align-items: flex-start; }
.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--r-sm); padding: 3px; margin-bottom: 16px; flex-wrap: wrap; }
.seg button { background: none; border: 0; color: var(--muted); padding: 7px 12px; border-radius: 7px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }

/* Filamente */
.fstat { display: flex; gap: 18px; color: var(--muted); margin-bottom: 14px; font-size: .92rem; }
.fstat b { color: var(--text); }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.fcard { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; cursor: pointer; transition: border-color .15s, transform .15s; }
.fcard:hover { border-color: #4a4a50; transform: translateY(-2px); }
.fcard.empty-spool { opacity: .5; }
.fimg { aspect-ratio: 16 / 10; background: radial-gradient(circle closest-side, #161618 0 22%, var(--c) 23% 66%, color-mix(in srgb, var(--c) 60%, #000) 67% 86%, var(--panel2) 87%); display: grid; place-items: center; }
.fimg img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.spool-ic { display: none; }
.fbody { padding: 12px 14px 14px; }
.fbody h4 { font-size: .98rem; margin-bottom: 6px; }
.fmeta { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; min-height: 22px; }
.bar { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin-bottom: 8px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.low i { background: var(--neg); }
.frow { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .92rem; }
.fquick { position: absolute; top: 8px; right: 8px; }
.fquick .icon-btn { background: rgba(12,12,13,.75); color: #fff; backdrop-filter: blur(6px); }
.swatch { width: 22px; height: 22px; border-radius: 50%; background: var(--c); border: 2px solid rgba(255,255,255,.15); flex-shrink: 0; display: inline-block; }

/* Standorte */
.lgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.lcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; cursor: pointer; }
.lcard:hover { border-color: #4a4a50; }
.limg { aspect-ratio: 4 / 3; background: var(--panel2); display: grid; place-items: center; }
.limg img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.lbody { padding: 14px 16px; }
.lbody h4 { margin-bottom: 4px; } .lbody p { margin: 0 0 8px; font-size: .9rem; }

/* Rechner */
.calc-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.sticky { position: sticky; top: 20px; }
.pos-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.pos { display: grid; grid-template-columns: 1fr 130px 34px; gap: 8px; align-items: center; }
.cline { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.cline span small { display: block; color: var(--muted); font-size: .78rem; }
.cline.total { border-bottom: 0; padding-top: 14px; font-size: 1.25rem; }
.cline.total b { color: var(--accent2); }
.pgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0 10px; }
.pgrid > div { background: var(--panel2); border-radius: var(--r-sm); padding: 10px 12px; }
.pgrid span { display: block; font-size: .78rem; color: var(--muted); }
.pgrid b { font-size: 1.2rem; white-space: nowrap; } .pgrid small { display: block; color: var(--muted); }
.calc-line { margin: 14px 0 0; color: var(--muted); } .calc-line b { color: var(--text); }
.sp-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; max-width: 520px; }
.sp-row { display: grid; grid-template-columns: 1fr 120px 34px; gap: 8px; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.65); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.modal.wide { width: min(780px, 100%); }
.modal-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body p { white-space: pre-line; }
.modal-foot { display: flex; gap: 8px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: #2a2a2e; border: 1px solid var(--line2); border-left: 4px solid var(--pos); padding: 11px 18px; border-radius: 10px; opacity: 0; transition: .25s; z-index: 99; max-width: 90vw; }
.toast.err { border-left-color: var(--neg); } .toast.warn { border-left-color: var(--warn); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Kundenansicht */
.quote { background: #fff; color: #111; border-radius: 12px; padding: 28px; }
.q-head { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.q-head img { width: 44px; height: 44px; border-radius: 10px; }
.q-head b { display: block; font-size: 1.1rem; } .q-head small { color: #666; }
.quote h2 { font-size: 1.6rem; } .quote .muted { color: #666; margin: 4px 0 0; }
.q-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin: 22px 0; padding: 18px 0; border-top: 1px solid #e5e5e5; border-bottom: 1px solid #e5e5e5; }
.q-grid span { display: block; font-size: .8rem; color: #666; } .q-grid b { font-size: 1.05rem; }
.q-price { display: flex; justify-content: space-between; align-items: baseline; }
.q-price b { font-size: 2.2rem; color: #e06d0c; letter-spacing: -.02em; }
.q-foot { color: #666; font-size: .82rem; margin: 18px 0 0; }

/* Login */
.login { display: grid; place-items: center; min-height: 100vh; width: 100%; padding: 20px; }
.login .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; padding: 30px; }
.login .field { text-align: left; }
.login-logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 16px; }
.login-links { display: flex; justify-content: space-between; font-size: .88rem; }
.err { color: var(--neg); min-height: 1.2em; margin: 0; font-size: .9rem; }

/* Responsive */
@media (max-width: 1050px) {
  .calc-layout, .grid2 { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .side { position: fixed; bottom: 0; top: auto; left: 0; right: 0; width: 100%; height: auto; flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 40; }
  .brand, .side-foot { display: none; }
  .side nav { flex-direction: row; width: 100%; justify-content: space-around; overflow-x: auto; }
  .side nav a { flex-direction: column; gap: 3px; padding: 6px 6px; font-size: .66rem; min-width: 52px; }
  .side nav a .ic { width: 21px; height: 21px; }
  .side nav a .nl { display: none; } .side nav a .ns { display: inline; }
  main { padding: 18px 14px 100px; }
  h1 { font-size: 1.4rem; }
  .form-grid > .half, .form-grid > .third { grid-column: span 6; }
  .fgrid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi b { font-size: 1.35rem; }
  .pos { grid-template-columns: 1fr 100px 34px; }
  .toolbar select { flex: 1 1 45%; }
}

@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; padding: 0; }
  .modal-wrap { background: none; backdrop-filter: none; position: absolute; }
  .modal { box-shadow: none; border: 0; max-height: none; }
  .quote { padding: 10mm; }
}

.calc-side { min-width: 0; }
.calc-layout .card > .field { margin-top: 14px; }
