:root {
  --bg: #f4f6f6; --card: #ffffff; --fg: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --primary: #0f766e; --primary-fg: #fff; --danger: #dc2626; --ok: #16a34a; --warn: #f59e0b;
  --radius: 14px; --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1214; --card: #152024; --fg: #e5eef0; --muted: #8aa0a6; --line: #223238; --primary: #14b8a6; --primary-fg: #04201c; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button, .action { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: var(--safe-top); background: var(--bg); }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 19px; margin: 0; flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { font-size: 13px; color: var(--muted); }
.iconbtn { font-size: 24px; line-height: 1; width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.iconbtn:active { background: var(--line); }
.iconbtn.danger { color: var(--danger); font-size: 20px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.offline { background: var(--warn); } .dot.error { background: var(--danger); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(30px + var(--safe-bottom)); }

/* Liste */
.searchrow { padding: 10px 14px 6px; }
.searchrow input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); outline: none; font-size: 16px; }
.chips { display: flex; gap: 6px; padding: 0 14px 8px; overflow-x: auto; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.chip.active { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.list { flex: 1; overflow-y: auto; padding: 4px 14px 110px; -webkit-overflow-scrolling: touch; }
.item { background: var(--card); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; display: flex; gap: 12px; align-items: center; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.item img { width: 84px; height: 52px; object-fit: cover; border-radius: 8px; background: #ddd; flex-shrink: 0; }
.item .body { flex: 1; min-width: 0; }
.item .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .c { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .cat { display: inline-block; font-size: 12px; margin-top: 4px; background: rgba(15,118,110,.12); color: var(--primary); border-radius: 6px; padding: 1px 7px; }
.item .call { width: 44px; height: 44px; border-radius: 50%; background: var(--primary); color: var(--primary-fg); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.fab { position: fixed; right: 20px; bottom: calc(24px + var(--safe-bottom)); width: 62px; height: 62px; border-radius: 50%; background: var(--primary); color: var(--primary-fg); font-size: 28px; box-shadow: 0 6px 16px rgba(0,0,0,.25); }

/* Scan / Formular */
.photos { display: flex; gap: 10px; padding: 14px 14px 6px; }
.photobox { flex: 1; aspect-ratio: 16/10; background: var(--card); border: 2px dashed var(--line); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 14px; overflow: hidden; position: relative; cursor: pointer; }
.photobox img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photobox .ph { line-height: 1.3; }
.photobox.has .ph { display: none; }
.photobox .toggle { position: absolute; right: 6px; bottom: 6px; font-size: 12px; background: rgba(15,23,42,.75); color: #fff; border-radius: 999px; padding: 4px 10px; z-index: 2; }
.primary { background: var(--primary); color: var(--primary-fg); font-weight: 600; padding: 13px 16px; border-radius: 12px; }
.primary:disabled { opacity: .5; }
.wide { display: block; width: calc(100% - 28px); margin: 8px 14px; }
.form { padding: 6px 14px; display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form label small { font-weight: normal; }
.form input, .form textarea { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg); outline: none; font-size: 16px; }
.form input:focus, .form textarea:focus { border-color: var(--primary); }
.row2 { display: flex; gap: 10px; } .row2 label { flex: 1; min-width: 0; }

/* Detail */
.cardimgs { padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 10px; }
.cardimgs img { width: 100%; border-radius: var(--radius); box-shadow: 0 2px 8px rgba(0,0,0,.15); background: #ddd; }
.actions { display: flex; gap: 6px; padding: 8px 14px; }
.action { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--card); border-radius: 12px; padding: 10px 4px; font-size: 20px; border: 1px solid var(--line); }
.action span { font-size: 11px; color: var(--muted); }
.action.disabled { opacity: .35; pointer-events: none; }
.fields { padding: 6px 14px; }
.field { background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.field .k { font-size: 12px; color: var(--muted); }
.field .v { font-size: 16px; margin-top: 2px; word-break: break-word; }
.field .v a { color: var(--primary); text-decoration: underline; }

/* Overlay / Toast */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; gap: 14px; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: 90%; text-align: center; }
