:root {
    color-scheme: light dark;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fbfc;
  --text: #182126;
  --muted: #64707d;
  --border: #d9e2e8;
  --primary: #0f6b72;
  --primary-dark: #0b5459;
  --success: #166534;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 16px;
  background: linear-gradient(180deg, #eef4f6 0%, #f6f8fa 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

body::before {
  content: "";
  display: block;
  height: env(safe-area-inset-top);
}

.app-shell {
  max-width: 860px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
  padding: 18px;
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(217, 226, 232, 0.85);
  border-radius: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand img {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  flex: 0 0 auto;
  box-shadow: 0 4px 14px rgba(15, 107, 114, 0.18);
  background: #fff;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.brand-copy p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

h2 {
  margin: 22px 0 10px;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

h3 {
  margin: 0 0 10px;
  font-size: 0.98rem;
}

label {
  display: block;
  margin: 0 0 6px;
  font-weight: 650;
  color: var(--text);
  font-size: 0.95rem;
}

input,
select,
textarea {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 107, 114, 0.12);
  background: #fcfeff;
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.row-actions {
  margin-top: 12px;
}

.inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.inline label {
  margin: 0;
}

.checkbox-row input[type="checkbox"] {
  width: 22px;
  min-height: 22px;
  height: 22px;
  margin: 0 6px 0 0;
  accent-color: var(--primary);
}

.card {
  margin: 10px 0 14px;
  padding: 16px;
  border: 1px solid rgba(217, 226, 232, 0.95);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.locked {
  background: #fff3f3;
  border-color: #f3b3b3;
}

.readonly input,
.readonly select,
.readonly textarea,
.readonly button.btn-primary {
  opacity: 0.65;
}

.small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.danger,
.ok {
  padding: 12px 14px;
  border-radius: 14px;
  margin: 10px 0;
  font-weight: 650;
}

.danger:empty,
.ok:empty {
  display: none;
}

.danger {
  color: var(--danger);
  background: #fef3f2;
  border: 1px solid #fecdca;
}

.ok {
  color: var(--success);
  background: #ecfdf3;
  border: 1px solid #b7ebc6;
}

.btn,
a.btn,
.top-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: #eef4f6;
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.btn:active,
a.btn:active,
.top-actions a:active {
  transform: translateY(1px);
}

.btn:hover,
a.btn:hover,
.top-actions a:hover {
  background: #e8eff2;
}

.btn-primary {
  width: 100%;
  margin-top: 18px;
  min-height: 56px;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(15, 107, 114, 0.24);
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
}

.btn-icon {
  min-width: 50px;
  padding-inline: 10px;
}

.top-actions a {
  border: 1px solid var(--border);
  background: #eef4f6;
}

hr {
  border: 0;
  border-top: 1px solid #e8edf1;
  margin: 18px 0;
}

canvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 1px dashed #9eb2bd;
  border-radius: 16px;
  background: #fcfeff;
  touch-action: none;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #edf1f4;
  font-size: 0.95rem;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.w-qty { width: 88px; }
.w-art { width: 160px; }
.w-dim { width: 130px; }
.w-del { width: 64px; }

.spacer-top {
  margin-top: 10px;
}

.sig-wrap {
  display: none;
  margin-top: 10px;
}

@media (max-width: 680px) {
  body {
    padding: 12px;
  }

  .topbar {
    padding: 16px;
    border-radius: 18px;
  }

  .card {
    padding: 14px;
    border-radius: 15px;
  }

  th,
  td {
    font-size: 0.9rem;
    padding: 8px 6px;
  }

  .btn,
  .top-actions a {
    width: 100%;
  }
}

@media (min-width: 760px) {
  body {
    padding: 24px;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .row {
    grid-template-columns: 1fr 1fr;
  }

  .btn-primary {
    position: sticky;
    bottom: 14px;
    z-index: 20;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11181c;
    --surface: #182126;
    --surface-soft: #1f2a30;
    --text: #ecf3f6;
    --muted: #9fb0ba;
    --border: #2a3941;
    --primary: #39a4ac;
    --primary-dark: #2b8b92;
    --success: #4ade80;
    --danger: #ff7b72;
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }

  body {
    background: linear-gradient(180deg, #0f1518 0%, #131b1f 100%);
  }

  .topbar {
    background: rgba(24, 33, 38, 0.88);
    border-color: rgba(42, 57, 65, 0.95);
  }

  .brand img {
    background: #10181c;
  }

  input,
  select,
  textarea {
    background: #121a1f;
    color: var(--text);
    border-color: var(--border);
  }

  input:focus,
  select:focus,
  textarea:focus {
    background: #162127;
    box-shadow: 0 0 0 4px rgba(57, 164, 172, 0.18);
  }

  .card {
    background: var(--surface);
    border-color: rgba(42, 57, 65, 0.95);
  }

  .btn,
  a.btn,
  .top-actions a {
    background: #1b252b;
    color: var(--text);
    border-color: var(--border);
  }

  .btn:hover,
  a.btn:hover,
  .top-actions a:hover {
    background: #223038;
  }

  .btn-primary {
    color: #ebf5f7;
    box-shadow: 0 10px 24px rgba(57, 164, 172, 0.18);
  }

  th,
  td {
    border-bottom-color: #243139;
  }

  hr {
    border-top-color: #243139;
  }

  canvas {
    background: #10181c;
    border-color: #3b505b;
  }

  .danger {
    background: rgba(180, 35, 24, 0.16);
    border-color: rgba(255, 123, 114, 0.35);
    color: #ffb4ae;
  }

  .ok {
    background: rgba(22, 101, 52, 0.18);
    border-color: rgba(74, 222, 128, 0.35);
    color: #86efac;
  }
}

@media (max-width: 680px) {
  /* bestehende Regeln … */

  /* Mitarbeiter-Tabelle stapeln */
  #employees table,
  #employees thead,
  #employees tbody,
  #employees tr,
  #employees th,
  #employees td {
    display: block;
    width: 100%;
  }

  #employees thead {
    display: none;
  }

  #employees tbody tr {
    margin-bottom: 14px;
    padding: 14px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
  }

  #employees td {
    border: 0;
    padding: 0;
    margin-bottom: 12px;
  }

  #employees td:last-child {
    margin-bottom: 0;
  }

  #employees td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
  }

  #employees td[data-label="Aktion"]::before {
    display: none;
  }

  #employees .btn-icon {
    width: 100%;
  }

  /* Material-Tabelle stapeln */
  #materials table,
  #materials thead,
  #materials tbody,
  #materials tr,
  #materials th,
  #materials td {
    display: block;
    width: 100%;
  }

  #materials thead {
    display: none;
  }

  #materials tbody tr {
    margin-bottom: 14px;
    padding: 14px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
  }

  #materials td {
    border: 0;
    padding: 0;
    margin-bottom: 12px;
  }

  #materials td:last-child {
    margin-bottom: 0;
  }

  #materials td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
  }

  #materials td[data-label="Aktion"]::before {
    display: none;
  }

  #materials .btn-icon {
    width: 100%;
  }
}