/* Hanemann Handwerker-App – Corporate Design wie das ERP (Rot/Grau auf Weiss, roter Balken oben) */
:root {
    --brand-red: #e2001a;
    --brand-red-dark: #b50015;
    --brand-red-soft: #fdecee;
    --brand-gray: #6d6e70;
    --ink: #2e2f31;
    --muted: #6d6e70;
    --line: #e4e4e6;
    --line-strong: #cfd0d3;
    --canvas: #f5f5f6;
    --white: #ffffff;
    --ok: #1f7a3f;
    --ok-soft: #e7f4ec;
    --warn: #8a5a00;
    --warn-soft: #fff4dc;
    --radius: 10px;
    --radius-sm: 6px;
    --tabbar-h: 62px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    min-height: 100vh;
    background: var(--canvas);
    font-size: 16px;
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    border-top: 5px solid var(--brand-red);
}
[hidden] { display: none !important; }
.sprite { display: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--brand-red-dark); }
h1, h2, h3 { color: var(--ink); margin: 0; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }

/* Kopf */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px; background: var(--white);
    border-bottom: 1px solid var(--line);
    min-height: 56px;
}
.brand { height: 28px; width: auto; }
.topbar-title { flex: 1; font-weight: 600; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: none; padding: 6px; margin-left: -6px; color: var(--ink); border-radius: var(--radius-sm); }
.sync-chip {
    border: 1px solid var(--line-strong); background: var(--white); color: var(--muted);
    border-radius: 999px; padding: 4px 10px; font-size: .78rem; display: flex; gap: 6px; align-items: center;
}
.sync-chip.is-offline { color: var(--warn); border-color: #e9c98a; background: var(--warn-soft); }
.sync-chip.is-pending { color: var(--brand-red-dark); border-color: #f2b8bf; background: var(--brand-red-soft); }
.sync-chip svg { width: 16px; height: 16px; }

.view { padding: 14px 14px calc(var(--tabbar-h) + 80px + var(--safe-bottom)); max-width: 820px; margin: 0 auto; outline: none; }

/* Fusszeile */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--white); border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom); height: calc(var(--tabbar-h) + var(--safe-bottom));
}
.tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: .72rem; border-top: 3px solid transparent;
}
.tabbar a.is-active { color: var(--brand-red); border-top-color: var(--brand-red); background: var(--brand-red-soft); }

.timer-bar {
    position: fixed; left: 10px; right: 10px; z-index: 25;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
    display: flex; align-items: center; gap: 10px;
    background: var(--ink); color: var(--white); border-radius: var(--radius);
    padding: 8px 10px 8px 14px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
    max-width: 800px; margin: 0 auto;
}
.timer-text { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.timer-text span { color: #c9c9cc; font-size: .88rem; }

/* Bausteine */
.card {
    background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px; margin-bottom: 12px;
}
.card.is-link { cursor: pointer; }
.card.is-link:active { background: var(--canvas); }
.card-accent { border-left: 4px solid var(--brand-red); }
.card-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.card-title { font-weight: 600; font-size: 1rem; }
.time { font-weight: 700; color: var(--brand-red-dark); font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .82rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.stack > * + * { margin-top: 6px; }
.section-title {
    font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
    font-weight: 700; margin: 18px 2px 8px;
}
.pill {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
    background: var(--canvas); border: 1px solid var(--line); font-size: .78rem; color: var(--muted);
}
.pill-red { background: var(--brand-red-soft); border-color: #f2b8bf; color: var(--brand-red-dark); }
.pill-ok { background: var(--ok-soft); border-color: #b9dcc6; color: var(--ok); }
.pill-warn { background: var(--warn-soft); border-color: #e9c98a; color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.info-lines { display: grid; gap: 6px; margin-top: 8px; }
.info-line { display: flex; gap: 8px; align-items: flex-start; color: var(--ink); text-decoration: none; }
.info-line svg { color: var(--brand-gray); width: 20px; height: 20px; margin-top: 1px; }
a.info-line { color: var(--brand-red-dark); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid var(--line-strong); background: var(--white); color: var(--ink);
    border-radius: var(--radius-sm); padding: 10px 14px; font: inherit; font-weight: 600; font-size: .95rem;
    min-height: 44px; cursor: pointer; text-decoration: none;
}
.btn svg { width: 19px; height: 19px; }
.btn-primary { background: var(--brand-red); border-color: var(--brand-red); color: var(--white); }
.btn-primary:active { background: var(--brand-red-dark); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--brand-red-dark); }
.btn-small { min-height: 34px; padding: 6px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1 1 auto; }

.datebar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.datebar .label { flex: 1; text-align: center; font-weight: 600; }
.datebar .btn { min-height: 40px; padding: 6px 10px; }

.segmented { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 12px; background: var(--white); }
.segmented button { flex: 1; border: 0; background: none; padding: 9px 6px; font: inherit; font-size: .88rem; color: var(--muted); }
.segmented button.is-active { background: var(--brand-red-soft); color: var(--brand-red-dark); font-weight: 600; box-shadow: inset 0 -3px 0 var(--brand-red); }

/* Formulare */
label.field { display: block; margin-bottom: 12px; }
label.field > span, .field-label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
    width: 100%; font: inherit; font-size: 16px; color: var(--ink);
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 10px 11px; background: var(--white);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-red-soft); border-color: var(--brand-red); }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choice {
    border: 1px solid var(--line-strong); background: var(--white); border-radius: 999px;
    padding: 7px 12px; font: inherit; font-size: .9rem; color: var(--ink);
}
.choice.is-on { background: var(--brand-red-soft); border-color: var(--brand-red); color: var(--brand-red-dark); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.qty-row { display: grid; grid-template-columns: 1fr 92px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.qty-row:last-child { border-bottom: 0; }
.qty-row .code { color: var(--muted); font-size: .78rem; display: block; }
.qty-row input { text-align: right; }
.qty-row.is-filled .qty-label { font-weight: 600; color: var(--brand-red-dark); }
.tbl-row { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 8px; background: var(--canvas); }
.tbl-row .form-grid label.field { margin-bottom: 8px; }
.error-text { color: var(--brand-red-dark); font-size: .9rem; margin: 6px 0; }

/* Login */
.login { max-width: 420px; margin: 30px auto; }
.login .logo { display: block; width: 220px; max-width: 70%; margin: 10px auto 22px; }
.login h1 { font-size: 1.2rem; margin-bottom: 4px; }

/* Plantafel */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.board-col { flex: 0 0 78%; max-width: 300px; scroll-snap-align: start; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.board-col.is-me { border-color: var(--brand-red); }
.board-col-head { padding: 9px 12px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.board-col-head .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand-gray); }
.board-col-body { padding: 8px; display: grid; gap: 8px; }
.board-item { display: block; color: var(--ink); text-decoration: none; border: 1px solid var(--line); border-left: 4px solid var(--brand-gray); border-radius: var(--radius-sm); padding: 8px; font-size: .88rem; background: var(--white); }
.board-item.kind-installation { border-left-color: var(--brand-red); }
.board-item.kind-measurement { border-left-color: #2f6db5; }
.board-item.kind-delivery { border-left-color: #8a5a00; }

/* Chat */
.chat { display: grid; gap: 10px; }
.msg { max-width: 88%; background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 8px 11px; }
.msg.is-mine { margin-left: auto; background: var(--brand-red-soft); border-color: #f2c4ca; }
.msg.is-info { max-width: 100%; background: var(--canvas); text-align: center; font-size: .85rem; color: var(--muted); }
.msg .meta { font-size: .74rem; color: var(--muted); margin-bottom: 3px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg img { display: block; max-width: 100%; max-height: 300px; border-radius: 8px; margin-top: 4px; background: var(--canvas); min-height: 60px; min-width: 120px; }
.msg.is-pending { opacity: .75; border-style: dashed; }
.composer {
    position: fixed; left: 0; right: 0; z-index: 24;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom));
    background: var(--white); border-top: 1px solid var(--line); padding: 8px 10px;
    display: flex; gap: 6px; align-items: flex-end;
}
.composer textarea { min-height: 44px; max-height: 140px; flex: 1; padding: 10px; }
.composer .btn { min-height: 44px; padding: 8px 10px; }
.has-composer .view { padding-bottom: calc(var(--tabbar-h) + 150px + var(--safe-bottom)); }
.has-composer .timer-bar { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 70px); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 1px solid var(--line-strong); background: var(--white); border-radius: 999px; padding: 7px 13px; font: inherit; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.tabs button.is-active { background: var(--ink); border-color: var(--ink); color: var(--white); }

.lines { width: 100%; border-collapse: collapse; font-size: .88rem; }
.lines td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines tr.is-text td { color: var(--muted); font-style: italic; }
.lines tr.is-title td { font-weight: 700; }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.list-item svg { color: var(--brand-gray); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item:last-child { border-bottom: 0; }
button.list-item, .choice-reset { font: inherit; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; cursor: pointer; width: 100%; }
button.list-item:last-child { border-bottom: 0; }
.list-item small { display: block; color: var(--muted); font-size: .82rem; }

/* Unterschrift */
.sigpad { border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--white); touch-action: none; width: 100%; height: 180px; display: block; }

/* Bottom-Sheet */
dialog.sheet { border: 0; padding: 0; width: 100%; max-width: 640px; margin: auto auto 0; border-radius: 16px 16px 0 0; max-height: 92vh; }
dialog.sheet::backdrop { background: rgba(46,47,49,.45); }
.sheet-body { padding: 18px 16px calc(18px + var(--safe-bottom)); overflow-y: auto; max-height: 92vh; }
.sheet-body h2 { margin-bottom: 12px; }

.toast {
    position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
    background: var(--ink); color: var(--white); padding: 10px 16px; border-radius: 999px; font-size: .9rem;
    max-width: 92vw; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.is-error { background: var(--brand-red-dark); }

.watermark { position: fixed; right: -40px; bottom: 80px; width: 260px; opacity: .06; pointer-events: none; z-index: 0; }

@media (min-width: 720px) {
    .board-col { flex-basis: 260px; }
    .tabbar { max-width: 820px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
    .composer { max-width: 820px; margin: 0 auto; }
}

/* ---------- Aufbau wie Craftnote ---------- */

/* Suche */
.search { display: flex; align-items: center; gap: 8px; background: var(--white); border: 1px solid var(--line-strong);
    border-radius: 999px; padding: 0 14px; margin-bottom: 12px; }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { border: 0; outline: none; background: none; flex: 1; min-height: 44px; font: inherit; padding: 0; }

/* Projektliste */
.plist { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.plist > .card { margin: 0; border: 0; }
.prow { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.prow:last-child { border-bottom: 0; }
.prow:active { background: var(--canvas); }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
    background: var(--brand-red-soft); color: var(--brand-red-dark); font-weight: 700; font-size: .95rem; }
.avatar-small { width: 32px; height: 32px; font-size: .78rem; }
.prow-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.prow-top { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.prow-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-when { flex: none; font-size: .78rem; color: var(--muted); }
.prow-sub, .prow-msg { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-msg { color: var(--ink); }
.prow-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.prow-badges svg, .task-meta svg { width: 13px; height: 13px; }

/* Projekt-Reiter (Unterstrich wie Craftnote) */
.ptabs { display: flex; overflow-x: auto; margin: -14px -14px 12px; background: var(--white); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 5; scrollbar-width: none; }
.ptabs button { flex: 1 0 auto; border: 0; background: none; font: inherit; font-size: .9rem; color: var(--muted);
    padding: 12px 12px 10px; border-bottom: 3px solid transparent; white-space: nowrap; }
.ptabs button.is-active { color: var(--brand-red-dark); font-weight: 600; border-bottom-color: var(--brand-red); }

/* Umschalter als Links */
.segmented a { flex: 1; text-align: center; padding: 9px 6px; font-size: .88rem; color: var(--muted); text-decoration: none; }
.segmented a.is-active { background: var(--brand-red-soft); color: var(--brand-red-dark); font-weight: 600; box-shadow: inset 0 -3px 0 var(--brand-red); }
.segmented-small button { padding: 6px; font-size: .82rem; }

/* Chat */
.day-sep { text-align: center; margin: 6px 0; }
.day-sep span { display: inline-block; background: var(--white); border: 1px solid var(--line); border-radius: 999px;
    padding: 2px 10px; font-size: .74rem; color: var(--muted); }
.btn-round { border-radius: 50%; width: 44px; min-width: 44px; padding: 0; justify-content: center; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { border-radius: 22px; }

/* Listen in Karten ohne Innenabstand */
.card-flush { padding: 0 14px; }
.list-item small { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }

/* Aufgaben */
.task { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.task:last-child { border-bottom: 0; }
.task .check { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--white); margin-top: 1px; }
.task.is-done .check { background: var(--ok); border-color: var(--ok); box-shadow: inset 0 0 0 3px var(--white); }
.task.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task.is-pending { opacity: .75; }
.task-title { font-weight: 600; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .8rem; color: var(--muted); margin-top: 3px; }
.task-meta span { display: inline-flex; gap: 4px; align-items: center; }
.task-meta a { color: var(--brand-red-dark); }
.is-overdue { color: var(--brand-red-dark); font-weight: 600; }

/* Dateien */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.thumb { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: var(--line); border-radius: 4px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-tag { position: absolute; left: 4px; bottom: 4px; background: var(--brand-red); color: var(--white); font-size: .7rem; padding: 1px 6px; border-radius: 999px; }

/* Zeiten im Projekt */
.stopwatch { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stopwatch .big { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Formularvorlagen und Dokumentenerfassung */
.tpl .list-item { border: 0; padding-top: 0; }
.tpl .btn-row { margin-top: 4px; }
.ki-banner { border-left: 4px solid var(--warn); background: var(--warn-soft); }
.ki-banner p { margin: 6px 0; }
.mark, .is-uncertain { background: #fff1b8; }
.mark { padding: 0 4px; border-radius: 3px; }
.is-uncertain { border-radius: 6px; box-shadow: 0 0 0 4px #fff1b8; }
.reading { text-align: center; padding: 20px 6px; }
.spinner { width: 42px; height: 42px; margin: 0 auto 12px; border-radius: 50%; border: 4px solid var(--line);
    border-top-color: var(--brand-red); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer .btn-round { padding: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.prow-top strong { flex: 1; min-width: 0; }

/* Projekt-Übersicht (eine Seite) */
.ov-head { display: grid; gap: 10px; }
.ov-address { display: flex; gap: 8px; align-items: flex-start; text-align: left; color: var(--ink); font: inherit; }
.ov-address svg { flex: none; width: 18px; height: 18px; color: var(--brand-red); margin-top: 2px; }
.ov-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ov-act { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border: 1px solid var(--line);
    border-radius: 12px; background: var(--white); font: inherit; font-size: .78rem; color: var(--ink); }
.ov-act svg { width: 22px; height: 22px; color: var(--brand-red); }
.ov-act:disabled { opacity: .4; }
.ov-act.is-on { background: var(--brand-red); border-color: var(--brand-red); color: var(--white); }
.ov-act.is-on svg { color: var(--white); }
.ov-msg { margin-top: 4px; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.section-title.row-between { display: flex; align-items: baseline; }
.link-btn { border: 0; background: none; font: inherit; font-size: .85rem; color: var(--brand-red-dark); padding: 0; text-transform: none; letter-spacing: 0; }
.btn-block + .btn-block, .btn-block + .section-title { margin-top: 10px; }
.ov-head + .btn-block { margin-top: 12px; }

/* Aufgaben mit Dateien */
.task-attach { flex: none; border: 0; background: none; padding: 4px; color: var(--brand-gray); }
.task-attach svg { width: 20px; height: 20px; }
.task-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 3px 8px; border: 1px solid var(--line);
    border-radius: 999px; background: var(--white); font: inherit; font-size: .78rem; color: var(--ink); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.chip svg { width: 13px; height: 13px; flex: none; }
.task .grow { min-width: 0; }
.ov-last { display: block; color: inherit; text-decoration: none; }

/* Mitteilungen */
.bell-btn { position: relative; margin-left: 0; margin-right: -6px; }
.bell-btn svg { width: 24px; height: 24px; }
.bell-badge { position: absolute; top: 0; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
    background: var(--brand-red); color: var(--white); font-size: .68rem; font-weight: 700; line-height: 17px; text-align: center; }
.notif.is-unread strong { color: var(--brand-red-dark); }
.notif.is-unread { background: var(--brand-red-soft); margin: 0 -14px; padding-left: 16px; padding-right: 16px; width: calc(100% + 28px); }
.notif small + small { margin-top: 2px; }
