:root {
  --bg: #f4f3ef; --card: #fff; --ink: #1d2030; --mute: #6c7084; --line: #e3e1da; --line2: #c9c6bc;
  --acc: #0f6e6e; --acc-soft: #e2f1f0; --red: #d63a3a; --ok: #2e9e6b; --grp: #f7f6f2; --sel: #d5ebe9;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
#main { height: 100%; display: flex; flex-direction: column; }
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.btn { border: 1px solid var(--line2); background: var(--card); border-radius: 7px; padding: 6px 12px; white-space: nowrap; }
.btn:hover { border-color: var(--acc); }
.btn:disabled { opacity: .4; cursor: default; border-color: var(--line2); }
.btn.pri { background: var(--acc); border-color: var(--acc); color: #fff; }
.btn.danger { color: var(--red); }
.btn.icon { padding: 5px 9px; }
.inp { border: 1px solid var(--line2); border-radius: 7px; padding: 6px 9px; background: #fff; min-width: 0; width: 100%; }
.inp:focus { outline: 2px solid var(--acc-soft); border-color: var(--acc); }
.inp[readonly] { background: #f6f5f1; color: var(--mute); }
textarea.inp { resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; } .row.end { justify-content: flex-end; } .sp { flex: 1; }
.mute { color: var(--mute); } .small { font-size: 12px; }

/* Kopf */
.top { display: flex; align-items: center; gap: 6px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--acc); letter-spacing: .04em; text-decoration: none; margin-right: 14px; }
.top nav { display: flex; gap: 2px; }
.top nav a { padding: 6px 12px; border-radius: 7px; color: var(--mute); text-decoration: none; }
.top nav a.on { background: var(--acc-soft); color: var(--acc); font-weight: 600; }
.av { width: 26px; height: 26px; border-radius: 50%; background: #d9e6e5; color: #24504f; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 600; vertical-align: middle; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bar .inp { width: 240px; }
.bar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }

/* Projektverwaltung */
.pv { flex: 1; min-height: 0; display: flex; }
.pv-list { flex: 1; min-width: 0; overflow: auto; background: var(--card); }
.pv-side { width: 440px; flex: none; border-left: 1px solid var(--line2); background: var(--card); display: flex; flex-direction: column; }
.pv-side header { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.pv-side header b { font-size: 16px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-side .body { flex: 1; overflow: auto; padding: 4px 16px 16px; }
.pv-side footer { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.pv-side .none { padding: 40px 20px; text-align: center; color: var(--mute); }
table.tree { border-collapse: collapse; width: 100%; min-width: 980px; }
.tree th { position: sticky; top: 0; z-index: 2; background: #efede6; text-align: left; font-size: 12px; font-weight: 600; color: var(--mute); padding: 7px 8px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.tree td { padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }
.tree tr { cursor: default; }
.tree tr.g td { background: var(--grp); font-weight: 600; }
.tree tr:hover td { background: #faf9f6; }
.tree tr.sel td { background: var(--sel); }
.tree .tw { display: inline-block; width: 18px; text-align: center; color: var(--mute); cursor: pointer; user-select: none; }
.tree .ic { display: inline-block; width: 20px; text-align: center; }
.tree .cnt { font-weight: 400; color: var(--mute); font-size: 12px; margin-left: 6px; }
.tree .num { text-align: right; }
.pill { display: inline-block; padding: 0 8px; border-radius: 99px; font-size: 11px; line-height: 18px; border: 1px solid var(--line2); color: var(--mute); }
.pill.p1 { color: #8a5a00; border-color: #ecd79a; background: #fdf6e0; }
.pill.p2 { color: #1e5fa8; border-color: #c4d9f2; background: #edf4fd; }
.pill.p3 { color: var(--ok); border-color: #b9e0cd; background: #eef8f3; }
.empty { padding: 40px; text-align: center; color: var(--mute); }

/* Formulare */
.form label, .dlg label { display: block; font-size: 12px; color: var(--mute); margin: 10px 0 3px; }
.form .g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.form .g3 { display: grid; grid-template-columns: 1fr 2fr; gap: 0 10px; }
.form .g4 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 10px; }
.form details { border-bottom: 1px solid var(--line); padding: 6px 0 12px; }
.form details:not([open]) { padding-bottom: 6px; }
.form summary { cursor: pointer; font-weight: 600; color: var(--acc); padding: 6px 0; list-style-position: inside; }
.form .chk { display: flex; gap: 8px; align-items: center; margin-top: 12px; color: var(--ink); font-size: 14px; }
.hist { font-size: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.hist:last-child { border: 0; }
.hist s { color: var(--mute); }

/* Projektseite */
.wrap { padding: 20px; overflow: auto; flex: 1; }
.page { max-width: 1100px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.phead { padding: 18px 20px; display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.phead h1 { margin: 0; font-size: 22px; font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 20px; padding: 0 20px 18px; }
.facts small { display: block; color: var(--mute); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.mods { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 16px; }
.mod { padding: 16px; opacity: .65; }
.mod b { display: block; margin-bottom: 4px; }
table.plain { border-collapse: collapse; width: 100%; }
.plain th, .plain td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.plain th { font-size: 12px; color: var(--mute); font-weight: 600; }
.plain tr.click { cursor: pointer; } .plain tr.click:hover td { background: #faf9f6; }

/* Dialoge */
#modal { position: fixed; inset: 0; background: rgba(20, 22, 35, .4); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; }
.dlg { width: 460px; max-width: 100%; max-height: 100%; overflow: auto; padding: 18px; }
.dlg h3 { margin: 0 0 6px; } .dlg > .row { margin-top: 16px; } .dlg p { margin: 6px 0; }
#menu { position: fixed; z-index: 25; background: var(--card); border: 1px solid var(--line2); border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .15); min-width: 220px; overflow: hidden; }
#menu .mi { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 14px; }
#menu .mi:hover { background: #faf9f6; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 40; max-width: 90vw; }
.login { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 340px; max-width: 100%; padding: 24px; }
.login h2 { margin: 12px 0 4px; font-size: 18px; }
.login label { display: block; font-size: 12px; color: var(--mute); margin: 12px 0 4px; }
.login .btn { width: 100%; margin-top: 18px; }

@media (max-width: 900px) {
  .pv { flex-direction: column; }
  .pv-side { width: auto; border-left: 0; border-top: 1px solid var(--line2); max-height: 55%; }
  .bar .inp { width: 100%; }
}

/* Leistungsverzeichnis */
#lvtitle a { color: var(--acc); text-decoration: none; }
.tree.lv { min-width: 760px; table-layout: fixed; }
.tree.lv td { max-width: none; }
.tree.lv td[data-f] { cursor: text; }
.tree.lv tr.hw td { font-style: italic; color: #4a4e63; }
.tree.lv tr.off td { color: var(--mute); }
.tree.lv .lt { color: var(--acc); font-style: normal; font-weight: 400; }
.tree th.num { text-align: right; }
.cell { width: calc(100% - 20px); border: 1px solid var(--acc); border-radius: 4px; padding: 1px 4px; margin: -2px 0; background: #fff; font-weight: 400; font-style: normal; }
.tree td:not(:first-child) .cell { width: 100%; }
.cell.num { text-align: right; }
.lvfoot { display: flex; gap: 22px; padding: 9px 16px; border-top: 1px solid var(--line2); background: #efede6; font-size: 13px; }
#menu a.mi { display: block; padding: 9px 14px; color: inherit; text-decoration: none; }
#menu a.mi:hover { background: #faf9f6; }

/* Vergabe / Preisspiegel */
.link { color: var(--acc); cursor: pointer; text-decoration: underline; }
a.btn { text-decoration: none; display: inline-block; }
table.ps { border-collapse: collapse; min-width: 100%; }
.ps th, .ps td { padding: 5px 8px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; }
.ps thead th { position: sticky; top: 0; z-index: 2; background: #efede6; font-size: 12px; text-align: left; color: var(--mute); border-bottom: 1px solid var(--line2); }
.ps thead tr:nth-child(2) th { top: 47px; }
.ps th.bh { cursor: pointer; color: var(--ink); min-width: 190px; height: 47px; }
.ps th.bh:hover { background: var(--acc-soft); }
.ps th.bh b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.ps .num { text-align: right; }
.ps td.kt { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.ps tr.g td { background: var(--grp); font-weight: 600; }
.ps td.ep { cursor: text; }
.ps td.lo { background: #dff3e6; } .ps td.hi { background: #fbe1e1; } .ps td.miss { color: var(--red); }
.ps td.outb, .ps th.outb { color: var(--mute); background: #f6f5f1; }
.ps tfoot td { font-weight: 600; background: #f7f6f2; position: sticky; }
.ps tfoot tr:first-child td { border-top: 2px solid var(--line2); }
.ps tr.off td { color: var(--mute); }

/* Abrechnung */
.btn.on { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); font-weight: 600; }
.ps.ab td.cur { cursor: text; background: #fffbe6; min-width: 110px; }
.ps.ab td.lnb { cursor: pointer; color: var(--acc); text-align: center; }
.ps.ab td.lnb:hover { background: var(--acc-soft); }
.ps td.over { color: var(--red); font-weight: 600; }
table.calc tr.s td { font-weight: 600; border-top: 1px solid var(--line2); }
table.calc tr.b td { font-weight: 700; font-size: 14px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
table.calc td { padding: 5px 4px; }
.ln { display: grid; grid-template-columns: 1.4fr 1.2fr 90px 36px; gap: 6px; align-items: center; margin-bottom: 6px; }
.ln.head { font-size: 12px; color: var(--mute); margin: 10px 0 4px; }
.ln .q { text-align: right; font-variant-numeric: tabular-nums; }

/* Kostenermittlung */
.tree.kt tr.k1 td { font-size: 15px; background: #ebe9e1; }
.tree.kt tr.k2 td { background: var(--grp); }
.tree.kt tr.k3 td { background: #fbfaf7; }
.tree.kt tr.g td { cursor: default; }

/* Aufmaß */
.tree.am td.fm { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.plain tr.selrow td { background: var(--sel); }
.ln.ro { color: var(--mute); }
#menu .mh { padding: 8px 14px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); }

/* Ansichten: verschiebbare Spaltenköpfe */
th.vth { cursor: grab; user-select: none; }
.plain th.vth { position: relative; }
th.vth.vdrop { box-shadow: inset 3px 0 0 var(--acc); background: var(--acc-soft) !important; }
.vgrip { position: absolute; top: 0; right: -3px; bottom: 0; width: 8px; cursor: col-resize; z-index: 3; }
.vgrip:hover { background: var(--acc); opacity: .35; }
#menu .vcol { display: flex; gap: 8px; align-items: center; padding: 6px 14px; cursor: pointer; }
#menu .mi:disabled { opacity: .4; cursor: default; }
