:root {
  --primary: #6D28D9;
  --primary-dark: #5B21B6;
  --primary-tint: #F5F2FF;
  --grad: linear-gradient(135deg, #8B5CF6 0%, #6D28D9 55%, #5B21B6 100%);
  --bg: #F2F4F7;
  --card: #FFFFFF;
  --input-bg: #FFFFFF;
  --text: #1A1D21;
  --muted: #6B7280;
  --border: #E5E7EB;
  --danger: #D64545;
  --ok: #2E9E5B;
}

[data-theme="dark"] {
  --bg: #12131A;
  --card: #1E1F28;
  --input-bg: #1B1C25;
  --text: #E7E8EE;
  --muted: #9AA0AE;
  --border: #34363F;
  --primary-tint: #2A2340;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

button { -webkit-user-select: none; user-select: none; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

body {
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--grad);
  color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

.appbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.steps {
  display: flex;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  gap: 8px;
}

.steps li {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.7);
  padding: 6px 4px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  cursor: pointer;
}

.steps li .dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.steps li.active {
  background: #fff;
  color: var(--primary);
}

.steps li.active .dot {
  background: var(--grad);
  color: #fff;
}

.steps li.done {
  color: #fff;
  background: rgba(255,255,255,.2);
}

.steps li.done .dot {
  background: var(--ok);
}

main {
  padding: 16px;
}

#view-project, #view-done {
  max-width: 720px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

input[type="text"], input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  -webkit-appearance: none;
}

input[type="text"]:focus, input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109,40,217,.15);
}

.btn {
  display: block;
  width: 100%;
  padding: 15px;
  font-size: 17px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
}

.btn.primary {
  background: var(--grad);
  color: #fff;
}
.btn.primary:active { background: var(--primary-dark); }
.btn.primary:disabled { background: #B9C4D0; }

.btn.ghost {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn.ghost:active { background: var(--primary-tint); }

/* ---------- Schritt 1: Projekte ---------- */
.project-intro { font-size: 15px; font-weight: 600; margin: 4px 2px 14px; }

.project-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.project-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
}
.project-card:active { border-color: var(--primary); background: var(--primary-tint); }

.project-arrow { color: var(--muted); font-size: 22px; }

/* ---------- Schritt 2: Katalog ---------- */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tab {
  flex: 1;
  padding: 12px 4px;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active {
  background: var(--grad);
  color: #fff;
  border-color: var(--primary);
}

.catalog-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.back-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--primary);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.back-btn:active { background: var(--primary-tint); }

.catalog-title { font-size: 16px; font-weight: 700; color: var(--text); }

.catalog-hint {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 15px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.type-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
}
.type-card:active { background: var(--primary-tint); border-color: var(--primary); }

.type-img {
  width: 100%;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.type-img img {
  max-width: 100%;
  max-height: 96px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.type-card.no-img {
  min-height: 140px;
  justify-content: center;
}
.type-card.no-img .type-name { font-size: 16px; }

.type-name { font-size: 14px; font-weight: 600; color: var(--text); text-align: center; }

.badge {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--grad);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
}

.size-card {
  position: relative;
  padding: 20px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.size-card.has-qty { border-color: var(--primary); background: var(--primary-tint); }

.size-qty {
  position: absolute;
  top: 6px;
  right: 9px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
}

.qty-view {
  text-align: center;
  padding: 12px 0 8px;
}

.qty-cat {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.qty-title { font-size: 22px; font-weight: 700; margin: 6px 0 24px; }

.big-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  max-width: 440px;
  margin: 0 auto;
}

.big-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: var(--grad);
  color: #fff;
  font-size: 46px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.big-btn:active { background: var(--primary-dark); }

.big-input {
  width: 150px;
  font-size: 44px;
  font-weight: 700;
  text-align: center;
  padding: 10px 8px;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: var(--input-bg);
  color: var(--text);
  -webkit-appearance: none;
}
.big-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(109,40,217,.15); }

/* ---------- Schritt 3: Abschluss ---------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  font-size: 15px;
}

.success { text-align: center; padding: 24px 16px; }
.success-check {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 40px;
  line-height: 72px;
  margin: 0 auto 12px;
}
.success h2 { margin: 0 0 4px; }
.success p { color: var(--muted); margin: 0; }

.history-title { font-size: 15px; margin: 24px 4px 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.history { display: flex; flex-direction: column; gap: 10px; }

.history-entry {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  gap: 8px;
}

.history-entry .h-name { font-weight: 700; font-size: 15px; }
.history-entry .h-meta { font-size: 12px; color: var(--muted); }
.history-entry .h-del {
  border: none;
  background: none;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
}

.history-lines { margin-top: 10px; border-top: 1px solid var(--border); }
.history-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.history-line:last-child { border-bottom: none; }
.history-line .l-name { color: var(--text); }
.history-line .l-cat { color: var(--muted); font-size: 12px; }
.history-line .l-qty { font-weight: 700; white-space: nowrap; }

.summary-project {
  background: var(--grad);
  color: #fff;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.summary-project .sp-label { font-size: 12px; opacity: .8; }
.summary-project .sp-name { font-size: 19px; font-weight: 700; }

.summary-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.summary-line:last-child { border-bottom: none; }
.summary-line .l-name { flex: 1; }
.summary-line > div:first-child, .history-line > div:first-child { flex: 1; min-width: 0; }
.summary-line .l-cat { color: var(--muted); font-size: 12px; }
.summary-line .l-qty { font-weight: 700; white-space: nowrap; }

.summary-total {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 2px solid var(--border);
  font-weight: 700;
  font-size: 15px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
}
.modal-card h3 { margin: 0 0 14px; }
.modal-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  -webkit-appearance: none;
}
.modal-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(109,40,217,.15); }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; padding: 12px; font-size: 16px; }

/* ---------- Anmeldung ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  background: var(--grad);
  color: #fff;
}
.login-logo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  font-size: 44px;
  line-height: 84px;
  margin-bottom: 16px;
}
.login-title { font-size: 28px; font-weight: 800; margin: 0 0 6px; }
.login-sub { font-size: 15px; opacity: .85; margin: 0 0 28px; }
.login-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-form input {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  border: none;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  text-align: center;
  -webkit-appearance: none;
}
.login-form input:focus { outline: none; box-shadow: 0 0 0 3px rgba(255,255,255,.4); }
.login .btn.primary {
  background: #fff;
  color: var(--primary-dark);
}
.login .btn.primary:active { background: #f0ecff; }
.login-recent {
  margin-top: 22px;
  max-width: 320px;
  width: 100%;
  text-align: left;
}
.login .recent-label {
  font-size: 12px;
  opacity: .85;
  margin-bottom: 8px;
}
.login .chip {
  display: inline-block;
  background: rgba(255,255,255,.16);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  margin: 0 6px 6px 0;
  cursor: pointer;
}
.login .chip:active { background: rgba(255,255,255,.3); }

/* ---------- Appbar: Zahnrad ---------- */
.appbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.appbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.finish-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border: none;
  background: #fff;
  color: var(--primary);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px;
}
.finish-btn svg { width: 22px; height: 22px; display: block; }
.finish-btn:active { background: #f0ecff; }
.finish-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--ok);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.settings-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: rgba(255,255,255,.15);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.settings-btn svg { width: 20px; height: 20px; display: block; }
.settings-btn:active { background: rgba(255,255,255,.3); }

/* ---------- Einstellungen ---------- */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-head h3 { margin: 0; }
.modal-close {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}
.settings-user {
  font-size: 14px;
  color: var(--muted);
  padding: 10px 12px;
  background: var(--primary-tint);
  border-radius: 10px;
  margin-bottom: 16px;
}
.settings-section { margin-bottom: 16px; }
.settings-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.seg {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.seg button {
  flex: 1;
  padding: 10px 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg button.active {
  background: var(--grad);
  color: #fff;
}

/* ---------- Matrix ---------- */
.matrix-layout {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.matrix-side {
  width: 54px;
  flex-shrink: 0;
  border: none;
  border-radius: 14px;
  background: var(--grad);
  color: #fff;
  font-size: 30px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.matrix-side:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: default;
}
.matrix-side:active:not(:disabled) { filter: brightness(.88); }
.matrix-wrap {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  max-height: 72vh;
}
.matrix { table-layout: fixed; width: 100%; border-collapse: separate; border-spacing: 0; }
.matrix th, .matrix td {
  padding: 0;
  text-align: center;
  vertical-align: middle;
}
.matrix thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 10px 4px;
  white-space: nowrap;
}
.matrix th.corner {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 4;
  background: var(--card);
  width: 136px;
}
.matrix th.row-label {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
  border-right: 1px solid var(--border);
  width: 136px;
  padding: 6px 8px;
  text-align: left;
}
.row-label-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.row-img {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.row-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.row-name {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.matrix td { border-bottom: 1px solid var(--border); }
.matrix tbody tr:last-child td { border-bottom: none; }
.matrix-cell {
  width: 100%;
  height: 48px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px;
}
.matrix-cell.has-qty {
  background: var(--primary-tint);
  color: var(--primary);
}
.matrix-cell.selected {
  background: var(--primary);
  color: #fff;
}
.matrix-cell:active { background: var(--primary-tint); }

[data-theme="dark"] .type-img {
  background: #fff;
  border-radius: 10px;
  padding: 6px;
}
[data-theme="dark"] .row-img {
  background: #fff;
  border-radius: 5px;
  padding: 2px;
}
