:root {
  --bg: #070a10;
  --glass: rgba(255, 255, 255, 0.055);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.10);
  --text: #eef2f8;
  --muted: #93a0b5;
  --accent: #7aa2ff;
  --accent-2: #9b8cf0;
  --ok: #6fd6a4;
  --warn: #f0b45e;
  --danger: #ef7d8c;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
  max-width: 100vw;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: calc(96px + var(--safe-bottom)); }

.aurora {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.aurora span {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.42;
}
.aurora span:nth-child(1) { width: 340px; height: 340px; background: #2b4b9b; top: -110px; left: -90px; }
.aurora span:nth-child(2) { width: 300px; height: 300px; background: #5b3f9e; top: 34%; right: -130px; opacity: 0.32; }
.aurora span:nth-child(3) { width: 320px; height: 320px; background: #1d5f6b; bottom: -140px; left: 10%; opacity: 0.28; }

.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(28px) saturate(190%);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0 14px; }
.error-text { color: var(--danger); font-size: 14px; margin: 10px 0 0; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}
.login-card {
  width: 100%;
  max-width: 360px;
  padding: 34px 24px 28px;
  text-align: center;
}
.brand-mark { font-size: 44px; line-height: 1; margin-bottom: 10px; }
.login-card h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.4px; }
.login-card p { margin: 0 0 22px; font-size: 14px; }
.pin-input {
  width: 100%;
  padding: 15px 16px;
  font-size: 22px;
  letter-spacing: 8px;
  text-align: center;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 14px;
  outline: none;
}
.pin-input:focus { border-color: rgba(122, 162, 255, 0.55); }

/* ---------- Layout ---------- */
.app { max-width: 428px; margin: 0 auto; padding: 0 16px; }

.topbar {
  position: sticky;
  top: calc(8px + var(--safe-top));
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  margin: 8px 0 16px;
  border-radius: 20px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 22px; }
.topbar-title { font-weight: 650; font-size: 16px; letter-spacing: -0.2px; }
.cloud-pill { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.cloud-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.cloud-pill.ok .dot { background: var(--ok); box-shadow: 0 0 8px rgba(111, 214, 164, 0.7); }
.cloud-pill.err .dot { background: var(--danger); }

.icon-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 13px;
  font-size: 16px;
  cursor: pointer;
  flex: 0 0 auto;
}

.view-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; }
.view-head h2 { font-size: 26px; margin: 0; letter-spacing: -0.6px; }
.badge {
  background: rgba(122, 162, 255, 0.18);
  color: #b9ccff;
  border: 1px solid rgba(122, 162, 255, 0.28);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 15px;
  font-size: 15px;
  font-weight: 550;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, rgba(122, 162, 255, 0.92), rgba(155, 140, 240, 0.92));
  border-color: transparent;
  color: #0a0f1c;
  font-weight: 650;
  width: 100%;
}
.btn.ghost { background: rgba(255, 255, 255, 0.05); }
.btn.full { width: 100%; margin-top: 12px; }
.btn.danger { color: var(--danger); border-color: rgba(239, 125, 140, 0.35); }
.row { display: flex; }
.row.gap { gap: 10px; margin-top: 12px; }
.row.gap .btn { flex: 1; }

/* ---------- Scan ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.18);
}
.dropzone.dragover { border-color: var(--accent); background: rgba(122, 162, 255, 0.10); }
.drop-icon { font-size: 40px; }
.drop-title { font-weight: 600; font-size: 17px; }

.progress { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin-top: 14px; }
.progress-bar { height: 100%; width: 30%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

.upload-results { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Suche ---------- */
.search-box { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; border-radius: 18px; }
.search-box input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  padding: 10px 0;
}
.segmented {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px;
  margin: 12px 0 10px;
}
.segmented button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 4px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
}
.segmented button.active { background: rgba(255, 255, 255, 0.12); color: var(--text); }

/* ---------- Dokumente ---------- */
.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
.doc-card:active { transform: scale(0.985); background: var(--glass-strong); }
.doc-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
}
.doc-body { min-width: 0; flex: 1; }
.doc-title { font-weight: 600; font-size: 15px; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.doc-snippet { font-size: 12.5px; color: #b6c2d6; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-snippet mark { background: rgba(122, 162, 255, 0.28); color: #dbe6ff; border-radius: 4px; padding: 0 2px; }
.tag {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  color: #c3cee0;
}
.tag.review { color: var(--warn); border-color: rgba(240, 180, 94, 0.35); background: rgba(240, 180, 94, 0.10); }
.tag.synced { color: var(--ok); border-color: rgba(111, 214, 164, 0.3); background: rgba(111, 214, 164, 0.08); }
.tag.unsynced { color: var(--danger); border-color: rgba(239, 125, 140, 0.3); background: rgba(239, 125, 140, 0.08); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: rgba(122, 162, 255, 0.18); border-color: rgba(122, 162, 255, 0.4); color: #d6e2ff; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 14px; }

/* ---------- Settings ---------- */
.card { padding: 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.kv { display: flex; flex-direction: column; gap: 7px; font-size: 13.5px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; }
.kv span { color: var(--muted); }
.kv code { font-size: 12px; color: #c9d6ea; word-break: break-all; text-align: right; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + var(--safe-bottom));
  width: calc(100% - 24px);
  max-width: 404px;
  display: flex;
  justify-content: space-around;
  padding: 8px 6px;
  border-radius: 24px;
  z-index: 30;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 18px;
}
.tab small { font-size: 10px; font-weight: 550; }
.tab.active { color: var(--text); background: rgba(255, 255, 255, 0.09); }

/* ---------- Sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); }
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(26px + var(--safe-bottom));
  background: rgba(18, 22, 32, 0.86);
  animation: sheetUp 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.4; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.22); margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 4px; font-size: 19px; letter-spacing: -0.3px; }
.field { margin-top: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.field textarea { min-height: 90px; resize: vertical; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.ocr-preview {
  margin-top: 14px;
  max-height: 180px;
  overflow-y: auto;
  font-size: 12.5px;
  color: #b6c2d6;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 11px;
  white-space: pre-wrap;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom));
  background: rgba(24, 30, 42, 0.94);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 14px;
  font-size: 13.5px;
  z-index: 80;
  max-width: calc(100% - 40px);
  text-align: center;
  backdrop-filter: blur(20px);
}

/* ---------- Build-Footer ---------- */
.build-footer {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(2px + var(--safe-bottom));
  z-index: 25;
  pointer-events: none;
}
.build-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 9.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  pointer-events: auto;
  white-space: nowrap;
}
.build-badge { color: var(--ok); font-weight: 600; }
.build-sep { opacity: 0.4; }
.build-reload {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
