:root {
  --bg: #0B1220;
  --surface: #111A2E;
  --surface-2: #17233D;
  --surface-3: #1E2D4D;
  --border: #253556;
  --text: #F8FAFC;
  --text-muted: #94A3B8;
  --gold: #EAB308;
  --gold-soft: rgba(234, 179, 8, 0.14);
  --gold-text: #0B1220;
  --green: #10B981;
  --green-soft: rgba(16, 185, 129, 0.15);
  --amber: #F59E0B;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --red: #EF4444;
  --red-soft: rgba(239, 68, 68, 0.16);
  --sky: #38BDF8;
  --sky-soft: rgba(56, 189, 248, 0.15);
  --shadow: 0 10px 28px rgba(2, 6, 23, 0.35);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #F3F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --surface-3: #E2E8F0;
  --border: #CBD5E1;
  --text: #0F172A;
  --text-muted: #475569;
  --gold: #CA8A04;
  --gold-soft: rgba(202, 138, 4, 0.12);
  --gold-text: #FFFFFF;
  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.12);
  --amber: #D97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --red: #DC2626;
  --red-soft: rgba(220, 38, 38, 0.12);
  --sky: #0284C7;
  --sky-soft: rgba(2, 132, 199, 0.12);
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.num, .mono {
  font-variant-numeric: tabular-nums;
}
.mono { font-family: var(--mono); }

.bw-ico {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* App Shell */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.brand-text-col {
  min-width: 0;
  overflow: hidden;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1.5px solid var(--gold);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-title {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--green);
  white-space: nowrap;
}

.status-txt { display: inline; }

@media (max-width: 520px) {
  .top-header { padding: 0 8px; gap: 4px; }
  .brand-wrap { gap: 5px; }
  .brand-mark { width: 26px; height: 26px; border-radius: 7px; }
  .brand-title { font-size: 11.5px; letter-spacing: 0.01em; }
  .header-actions { gap: 4px; }
  .status-pill { padding: 4px 6px; }
  .status-txt { display: none; }
  .icon-btn { width: 30px; min-height: 30px; }
  .pill-btn { padding: 0 6px; font-size: 10.5px; min-height: 30px; gap: 3px; }
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.icon-btn, .pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}

.icon-btn { width: 36px; padding: 0; }
.icon-btn:hover, .pill-btn:hover { border-color: var(--gold); }
.icon-btn:active, .pill-btn:active { transform: scale(0.97); }

/* Body Layout */
.workspace {
  flex: 1;
  display: flex;
  min-width: 0;
}

.desktop-sidebar {
  display: none;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 14px 12px calc(92px + env(safe-area-inset-bottom));
  max-width: 1260px;
  margin: 0 auto;
  width: 100%;
}

.btn, .input, select, textarea, canvas.sig-canvas {
  scroll-margin-top: 72px;
  scroll-margin-bottom: 92px;
}

/* Mobile Bottom Nav (5 exact equal columns -> 0 overflow) */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}

.bnav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: 4px 2px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  min-width: 0;
}

.bnav-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.bnav-btn.active {
  color: var(--gold);
  background: var(--gold-soft);
}

@media (min-width: 640px) {
  .brand-sub { display: block; }
  .main-content { padding: 18px 18px calc(82px + env(safe-area-inset-bottom)); }
}

@media (min-width: 1024px) {
  .bottom-nav { display: none; }
  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    width: 244px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 14px 10px;
    gap: 4px;
    position: sticky;
    top: 58px;
    height: calc(100dvh - 58px);
    overflow-y: auto;
  }
  .main-content {
    padding: 22px 26px 40px;
  }
}

.snav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.snav-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.snav-btn.active {
  background: var(--gold-soft);
  color: var(--gold);
  border-color: rgba(234, 179, 8, 0.35);
  font-weight: 700;
}

/* Common UI Components */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 2px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.page-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card-soft {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  min-width: 0;
}

.card-gold {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid rgba(234, 179, 8, 0.45);
}

.card-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
.grid-3 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-val {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.text-gold { color: var(--gold); }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.text-sky { color: var(--sky); }

/* Badges & Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-gold { background: var(--gold-soft); color: var(--gold); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-sky { background: var(--sky-soft); color: var(--sky); }

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
}
.chip:hover { border-color: var(--gold); }
.chip.active {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 700;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  white-space: normal;
  line-height: 1.2;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: scale(0.98); }

.btn-sm {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
}

.btn-gold {
  background: var(--gold);
  color: var(--gold-text);
  border-color: var(--gold);
}

.btn-green {
  background: var(--green);
  color: #FFFFFF;
  border-color: var(--green);
}

.btn-red {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.35);
}

/* Sub-Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.tab-btn {
  flex: 1 1 auto;
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--gold);
  color: var(--gold-text);
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
}

.input-sm {
  min-height: 34px;
  padding: 4px 8px;
  font-size: 13px;
}

textarea { min-height: 78px; resize: vertical; }

.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
}

/* Tables (responsive horizontal container without page overflow) */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.bw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.bw-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.bw-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.num-col { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Signature Pad & Pin Board */
.sig-wrap {
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--bg);
  padding: 8px;
}

canvas.sig-canvas {
  width: 100%;
  height: 150px;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.pin-board {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0F172A;
  cursor: crosshair;
}

.pin-bg-img, .pin-bg-svg {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
}

.pin-layer {
  position: absolute;
  inset: 0;
}

.defect-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  color: #FFFFFF;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}
.pin-open { background: #DC2626; }
.pin-progress { background: #D97706; }
.pin-done { background: #059669; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

.photo-thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  height: 92px;
  background: var(--bg);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: rgba(11, 18, 32, 0.85);
  color: #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Progress Bars & Charts */
.bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--green);
}

/* Swiss QR-Bill Visual Preview */
.qr-bill-preview {
  background: #FFFFFF;
  color: #0F172A;
  border-radius: 12px;
  border: 1px solid #CBD5E1;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  font-size: 11.5px;
}
@media (min-width: 720px) {
  .qr-bill-preview {
    grid-template-columns: 180px minmax(0, 1fr);
  }
}

.qr-box-preview {
  background: #FFFFFF;
  padding: 6px;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-box-preview img {
  width: 156px;
  height: 156px;
  display: block;
}

/* Modals & Drawers */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(2, 6, 23, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 620px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(2, 6, 23, 0.65);
  display: none;
  justify-content: flex-end;
}

.drawer-backdrop.open {
  display: flex;
}

.drawer-panel {
  width: 100%;
  max-width: 440px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

/* Mobile More Sheet */
.more-sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

/* Toast */
#bw-toast {
  position: fixed;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  z-index: 90;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 12.5px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  max-width: 92vw;
  text-align: center;
}
#bw-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
@media (min-width: 1024px) {
  #bw-toast { bottom: 24px; }
}

.stack-sm > * + * { margin-top: 8px; }
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 16px; }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.row-gap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.bold { font-weight: 700; }

/* Baustellen-Turbo & Demo-Banner */
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-recording {
  border-color: var(--red) !important;
  color: var(--red) !important;
  background: rgba(239, 68, 68, 0.14) !important;
  animation: bwPulseRec 1.2s ease-in-out infinite;
}

@keyframes bwPulseRec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0); }
}

.sia-checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sia-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
}

.sia-pill.ok {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.12);
  color: var(--green);
}

.demo-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: 12px;
  border: 1px solid rgba(234, 179, 8, 0.45);
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  font-size: 12.5px;
}

/* 1-Klick Materialvarianten-Wechsler & OCR Prüf-Modal */
.variant-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.variant-chip {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.3;
}

.variant-chip:hover {
  border-color: var(--gold);
  color: var(--text);
}

.variant-chip.active {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

.ocr-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ocr-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1.8fr) 74px 72px;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.ocr-row.has-rate {
  grid-template-columns: 24px minmax(0, 1.5fr) 68px 66px 76px;
}

@media (max-width: 639px) {
  .ocr-row,
  .ocr-row.has-rate {
    grid-template-columns: 24px minmax(0, 1fr) 72px 72px;
  }
}
