:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #f0f1f4;
  --border: #dcdfe5;
  --text: #1d2027;
  --text2: #5d6472;
  --accent: #e85d00;
  --accent-text: #ffffff;
  --accent-soft: #fdeee3;
  --p1: #c62828; --p1-bg: #fde8e8;
  --p2: #d35400; --p2-bg: #fdeee3;
  --p3: #1f6fb5; --p3-bg: #e6f0fa;
  --p4: #5d6472; --p4-bg: #eceef2;
  --ok: #1e8e4e; --ok-bg: #e3f5ea;
  --warn: #9a6b00; --warn-bg: #fdf4d8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a; --surface: #1b1e27; --surface2: #242835; --border: #333849;
    --text: #e8eaf0; --text2: #9aa1b5; --accent-soft: #3a2414;
    --p1: #ff6b6b; --p1-bg: #3d1d1f; --p2: #ff9a4d; --p2-bg: #3a2414; --p3: #6cb2f0; --p3-bg: #172a3d; --p4: #9aa1b5; --p4-bg: #262a36;
    --ok: #4cd08a; --ok-bg: #16301f; --warn: #f0c35a; --warn-bg: #352b12;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141a; --surface: #1b1e27; --surface2: #242835; --border: #333849;
  --text: #e8eaf0; --text2: #9aa1b5; --accent-soft: #3a2414;
  --p1: #ff6b6b; --p1-bg: #3d1d1f; --p2: #ff9a4d; --p2-bg: #3a2414; --p3: #6cb2f0; --p3-bg: #172a3d; --p4: #9aa1b5; --p4-bg: #262a36;
  --ok: #4cd08a; --ok-bg: #16301f; --warn: #f0c35a; --warn-bg: #352b12;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; padding-bottom: calc(64px + var(--safe-bottom)); }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: .95rem; margin: 14px 0 8px; color: var(--text2); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--text2); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ── Kopf / Navigation ── */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 16px; padding: calc(8px + var(--safe-top)) 16px 8px; background: var(--surface); border-bottom: 3px solid var(--accent); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 600; white-space: nowrap; }
.brand-logo { height: 26px; width: auto; }
.topnav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topnav a, .bottomnav a { text-decoration: none; color: var(--text2); border-radius: 8px; position: relative; }
.topnav a { padding: 7px 11px; white-space: nowrap; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topright { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--p1); color: #fff; font-size: .72rem; line-height: 18px; text-align: center; font-weight: 700; }
.bottomnav { display: none; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text2); display: inline-block; }
.live-dot.on { background: var(--ok); }

@media (max-width: 1023px) {
  .topnav { display: none; }
  .brand span { display: none; }
  .topbar { padding: calc(6px + var(--safe-top)) 12px 6px; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; background: var(--surface); border-top: 1px solid var(--border); padding: 4px 4px calc(4px + var(--safe-bottom)); justify-content: space-around; }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 2px; font-size: .7rem; }
  .bottomnav a .ico { font-size: 1.25rem; line-height: 1.2; }
  .bottomnav a.active { color: var(--accent); font-weight: 600; }
  .bottomnav .badge { position: absolute; top: 0; right: 18%; }
}
@media (min-width: 1024px) { body { padding-bottom: 24px; } }

main { max-width: 1180px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* ── Bausteine ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.tight { padding: 10px 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; align-items: start; }
/* Am Handy: Arbeits- und Statusknoepfe nach oben, vor Beschreibung und Verlauf */
@media (max-width: 900px) { .detail-layout { display: flex; flex-direction: column; align-items: stretch; gap: 0; } .detail-layout > .col, .detail-layout #d-links { display: contents; } .detail-layout .aktion { order: -1; } }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .grid3 { grid-template-columns: 1fr; } }

button, .btn { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; min-height: 40px; }
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn-danger { color: var(--p1); }
.btn-big { padding: 14px 18px; font-size: 1.05rem; min-height: 52px; }
.btn-sm { padding: 4px 10px; min-height: 32px; font-size: .85rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-size: .85rem; color: var(--text2); margin: 10px 0 4px; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; font-size: .95rem; margin: 8px 0; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); min-height: 42px; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.err { color: var(--p1); margin: 8px 0 0; font-size: .9rem; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; white-space: nowrap; border: 0; border-radius: 0; border-right: 1px solid var(--border); min-height: 42px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.seg.prio button.on[data-v="1"] { background: var(--p1); }
.seg.prio button.on[data-v="2"] { background: var(--p2); }
.seg.prio button.on[data-v="3"] { background: var(--p3); }
.seg.prio button.on[data-v="4"] { background: var(--p4); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 12px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--surface2); color: var(--text2); }
.prio-1 { background: var(--p1-bg); color: var(--p1); }
.prio-2 { background: var(--p2-bg); color: var(--p2); }
.prio-3 { background: var(--p3-bg); color: var(--p3); }
.prio-4 { background: var(--p4-bg); color: var(--p4); }
.st-neu { background: var(--p1-bg); color: var(--p1); }
.st-zugewiesen { background: var(--p3-bg); color: var(--p3); }
.st-in_arbeit { background: var(--ok-bg); color: var(--ok); }
.st-wartet { background: var(--warn-bg); color: var(--warn); }
.st-erledigt { background: var(--accent-soft); color: var(--accent); }
.st-abgeschlossen { background: var(--surface2); color: var(--text2); }
.chip.neu { background: var(--p1); color: #fff; }

/* ── Listen ── */
.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } .filters .f-suche { grid-column: 1 / -1; } }
.tlist { display: flex; flex-direction: column; gap: 8px; }
.titem { display: grid; grid-template-columns: 6px 1fr auto; gap: 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); overflow: hidden; box-shadow: var(--shadow); }
.titem:hover { border-color: var(--accent); }
.titem .bar { background: var(--p3); }
.titem .bar.p1 { background: var(--p1); } .titem .bar.p2 { background: var(--p2); } .titem .bar.p4 { background: var(--p4); }
.titem .main { padding: 10px 0; min-width: 0; }
.titem .side { padding: 10px 12px 10px 0; text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.titem .t { font-weight: 600; overflow-wrap: anywhere; }
.titem .meta { font-size: .82rem; color: var(--text2); display: flex; gap: 4px 12px; flex-wrap: wrap; margin-top: 2px; }
.titem.done { opacity: .7; }
.working { color: var(--ok); font-weight: 600; }
.empty { padding: 28px; text-align: center; color: var(--text2); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { font-size: .8rem; color: var(--text2); text-transform: uppercase; letter-spacing: .03em; }
.tbl tr.off td { opacity: .5; }
.table-wrap { overflow-x: auto; }

/* ── Detail ── */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .93rem; }
.kv dt { color: var(--text2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 9px 0 9px 14px; border-left: 2px solid var(--border); margin-left: 6px; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.timeline li.kommentar::before { background: var(--p3); }
.timeline li.dokumentation::before { background: var(--ok); }
.timeline li.arbeit::before { background: var(--accent); }
.timeline .who { font-size: .8rem; color: var(--text2); }
.timeline .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline li.dokumentation .txt, .timeline li.kommentar .txt { background: var(--surface2); padding: 8px 10px; border-radius: 8px; margin-top: 3px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; background: var(--surface2); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photos .ph .x { position: absolute; top: 4px; right: 4px; min-height: 0; padding: 2px 7px; font-size: .8rem; background: rgba(0,0,0,.55); color: #fff; border: 0; }
.workbox { border: 2px solid var(--ok); background: var(--ok-bg); }
.workbox .timer { font-size: 1.6rem; font-weight: 700; color: var(--ok); font-variant-numeric: tabular-nums; }
.assignee { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.assignee:last-child { border-bottom: 0; }
.picklist { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; }

/* Laufende Arbeit unter dem Kopf */
#arbeit-banner .ab { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; background: var(--ok); color: #fff; }
#arbeit-banner .ab a { color: #fff; font-weight: 600; }
#arbeit-banner .ab .sp { flex: 1; min-width: 120px; overflow-wrap: anywhere; }
#arbeit-banner button { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.5); color: #fff; min-height: 34px; padding: 4px 12px; }

/* Dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.tile .n { font-size: 1.8rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { font-size: .82rem; color: var(--text2); }
.tile.alarm .n { color: var(--p1); }
.ma-row.idle td { color: var(--text2); }

/* Anlagenbaum */
.tree { list-style: none; padding-left: 0; margin: 0; }
.tree .tree { padding-left: 22px; border-left: 1px dashed var(--border); margin-left: 8px; }
.tree li > .node { display: flex; align-items: center; gap: 8px; padding: 5px 0; flex-wrap: wrap; }
.tree .node .lbl { flex: 1; min-width: 160px; }
.tree .node.off .lbl { opacity: .5; text-decoration: line-through; }
.tree .kz { font-family: Consolas, monospace; font-size: .82rem; color: var(--text2); }
.anlage-picker { position: relative; }
.anlage-results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; }
.anlage-results div { padding: 8px 11px; cursor: pointer; border-bottom: 1px solid var(--border); }
.anlage-results div:hover, .anlage-results div.hl { background: var(--accent-soft); }
.anlage-chosen { display: flex; align-items: center; gap: 8px; padding: 8px 11px; background: var(--accent-soft); border-radius: 8px; }
.anlage-chosen span { flex: 1; overflow-wrap: anywhere; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

/* Login */
.auth-box { max-width: 380px; margin: 8vh auto 0; }
.auth-box .brand-logo { height: 40px; display: block; margin: 0 auto 14px; }

.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--p1); color: #fff; }

dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: min(560px, calc(100vw - 24px)); width: 100%; background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg-body { padding: 18px; max-height: 80vh; overflow-y: auto; }
dialog.img { max-width: 96vw; background: #000; }
dialog.img img { display: block; max-width: 96vw; max-height: 90vh; margin: auto; }

/* Schaltbuch */
.sb-angefordert { background: var(--p3-bg); color: var(--p3); }
.sb-freigeschaltet { background: #c62828; color: #fff; }
.sb-zuschaltung_angefordert { background: var(--p2-bg); color: var(--p2); }
.sb-zugeschaltet { background: var(--ok-bg); color: var(--ok); }
.sb-storniert { background: var(--surface2); color: var(--text2); text-decoration: line-through; }
.sb-banner { padding: 12px 16px; border-radius: var(--radius); font-weight: 600; margin-bottom: 14px; }
.sb-banner.frei { background: #c62828; color: #fff; font-size: 1.05rem; }
.sb-banner.zu { background: var(--ok-bg); color: var(--ok); }
.sb-banner.anf { background: var(--p3-bg); color: var(--p3); }
.sb-banner.storno { background: var(--surface2); color: var(--text2); }
.sb-hinweis { border-color: var(--p2); background: var(--p2-bg); }
.sb-schritt:not(.done) { opacity: .65; }
.sb-nr { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: var(--surface2); align-items: center; justify-content: center; font-size: .85rem; margin-right: 4px; }
.sb-schritt.done .sb-nr { background: var(--accent); color: #fff; }

/* Druck (Schaltschein): nur der Inhalt, hell */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface2: #eee; --text: #000; --text2: #444; --border: #999; --shadow: none; color-scheme: light; }
  .topbar, .bottomnav, #arbeit-banner, .noprint, .toast, .aktion { display: none !important; }
  body { padding: 0; background: #fff; }
  main { max-width: none; padding: 0; }
  .detail-layout { display: block; }
  .card { break-inside: avoid; box-shadow: none; }
  .sb-schritt:not(.done) { opacity: 1; }
  .sb-banner.frei { background: #fff; color: #000; border: 3px solid #000; }
}

/* Einsatzplan */
.ez-wrap { padding: 0; overflow-x: auto; --ezname: 170px; }
@media (max-width: 600px) { .ez-wrap { --ezname: 110px; } }
.ez-grid { display: flex; flex-direction: column; }
.ez-row { display: grid; border-bottom: 1px solid var(--border); position: relative; min-height: 30px; }
.ez-row:last-child { border-bottom: 0; }
.ez-name { grid-column: 1; position: sticky; left: 0; z-index: 3; background: var(--surface); padding: 5px 10px; border-right: 1px solid var(--border); font-weight: 600; font-size: .88rem; display: flex; flex-direction: column; justify-content: center; overflow-wrap: anywhere; }
.ez-head { position: sticky; top: 0; z-index: 4; background: var(--surface); }
.ez-head .ez-name { color: var(--text2); font-weight: 600; font-size: .78rem; text-transform: uppercase; }
.ez-kopf { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; font-size: .72rem; color: var(--text2); padding: 4px 0 3px; border-left: 1px solid var(--border); line-height: 1.2; }
.ez-kopf b { font-size: .85rem; color: var(--text); }
.ez-kopf .kw { font-size: .65rem; color: var(--accent); font-weight: 700; }
.ez-kopf.we, .ez-tag.we { background: var(--surface2); }
.ez-kopf.heute b { color: #fff; background: var(--accent); border-radius: 10px; padding: 0 5px; }
.ez-tag { border-left: 1px solid var(--border); }
.ez-tag.heute { box-shadow: inset 2px 0 0 var(--accent); }
.ez-tag.over { background: repeating-linear-gradient(135deg, var(--p1-bg) 0 5px, transparent 5px 10px); box-shadow: inset 0 -3px 0 var(--p1); }
.ez-tag.klick { cursor: copy; }
.ez-tag.klick:hover { background: var(--accent-soft); }
.ez-bar, .ez-auf { z-index: 2; margin: 3px 2px; border-radius: 5px; font-size: .74rem; line-height: 22px; padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; min-width: 0; }
.ez-bar { color: #fff; font-weight: 600; }
.ez-bar.cut-l { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
.ez-bar.cut-r { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
.ez-auf { border: 1px dashed var(--text2); color: var(--text2); background: var(--surface); text-decoration: none; }
.ez-leg { display: inline-flex; align-items: center; gap: 6px; }
.ez-leg i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.ez-leg i.auf { border: 1px dashed var(--text2); }
.ez-leg i.over { background: var(--p1-bg); border: 1px solid var(--p1); }
