:root {
  --bg: #0b0d12;
  --bg-2: #12151d;
  --panel: #161a24;
  --panel-2: #1d2230;
  --line: #262c3b;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #7c7ff5;
  --accent-2: #ec4899;
  --accent-soft: rgba(124, 127, 245, .16);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --grad: linear-gradient(135deg, #6366f1, #ec4899);
  --sidebar: 232px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f9; --bg-2: #eceef4; --panel: #ffffff; --panel-2: #f3f4f8; --line: #e1e4ec;
    --text: #151824; --muted: #626a80; --accent-soft: rgba(99, 102, 241, .12);
    --shadow: 0 10px 40px rgba(20, 24, 40, .14); color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
img { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; font-size: 13px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ Layout */
#app { display: flex; min-height: 100vh; }
#sidebar {
  position: sticky; top: 0; height: 100vh; width: var(--sidebar); flex: none;
  display: flex; flex-direction: column; gap: 18px; padding: 20px 14px;
  background: var(--bg-2); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; padding: 0 8px; line-height: 1.05; }
.brand img { border-radius: 9px; }
.brand small { color: var(--muted); font-weight: 500; font-size: 12px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 550; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); }
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 6px; color: var(--muted); font-size: 13px; }
#main { flex: 1; min-width: 0; padding: 26px 30px 60px; outline: none; }
#bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-b)); background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
#bottom-nav .nav-item { flex-direction: column; gap: 3px; font-size: 11px; padding: 6px 8px; }
@media (max-width: 860px) {
  #sidebar { display: none; }
  #main { padding: 18px 14px calc(90px + var(--safe-b)); }
  h1 { font-size: 22px; }
}
@media (min-width: 861px) { #bottom-nav { display: none !important; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }

/* ------------------------------------------------------------------ Bausteine */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card h2 { margin-bottom: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: transform .08s, background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--grad); border: 0; color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border: 0; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 38px; padding: 0; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.badge.accent { color: #fff; background: var(--grad); border: 0; }
.badge svg, .chip svg, .stat svg { width: 13px; height: 13px; flex: none; }
svg { flex: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }

input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
select { padding-right: 30px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.field > span.hint { font-weight: 400; font-size: 12px; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 4px 0; }
.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--muted); font-size: 12.5px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 44px; height: 38px; padding: 3px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 99px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); cursor: pointer; user-select: none;
}
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; }
.chip.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty svg { width: 54px; height: 54px; opacity: .5; margin-bottom: 12px; }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { padding: 6px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.stat b { color: var(--text); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.code-box { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 8px 8px 12px; }
.code-box code { flex: 1; overflow-x: auto; white-space: nowrap; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.tabs { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--bg); border: 1px solid var(--line); gap: 2px; }
.tabs button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 13px; padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.tabs button.on { background: var(--panel-2); color: var(--text); }

/* ------------------------------------------------------------------ Galerie */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .search { flex: 1 1 220px; max-width: 340px; }
.toolbar select { width: auto; min-width: 140px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
@media (max-width: 560px) { .gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
.tile {
  position: relative; aspect-ratio: 16 / 10; border-radius: 12px; overflow: hidden; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); outline: 3px solid transparent; outline-offset: -3px;
  transition: transform .15s, outline-color .12s;
}
.tile:hover { transform: translateY(-2px); }
.tile img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s; }
.tile img.loaded { opacity: 1; }
.tile .meta {
  position: absolute; inset: auto 0 0 0; display: flex; align-items: center; gap: 6px; padding: 22px 9px 7px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65)); color: #fff; font-size: 12px; font-weight: 600;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .meta, .selecting .tile .meta { opacity: 1; }
.tile .fav { position: absolute; top: 7px; right: 7px; color: #fbbf24; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.tile .fav svg { width: 20px; height: 20px; }
.tile .sel {
  position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, .3); display: none; align-items: center; justify-content: center;
}
.selecting .tile .sel { display: flex; }
.tile.selected { outline-color: var(--accent); }
.tile.selected .sel { background: var(--accent); border-color: var(--accent); }
.tile.selected .sel::after { content: ""; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.sentinel { height: 40px; }

.bulkbar {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 24px);
  padding: 8px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
}
@media (max-width: 860px) { .bulkbar { bottom: calc(78px + var(--safe-b)); } }
.bulkbar .count { padding: 0 10px; font-weight: 700; }

/* ------------------------------------------------------------------ Gruppen / Geräte */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.group-card { padding: 0; overflow: hidden; cursor: pointer; transition: transform .15s; }
.group-card:hover { transform: translateY(-2px); }
.group-card .cover { aspect-ratio: 16 / 8; background: var(--panel-2) center / cover no-repeat; position: relative; }
.group-card .cover::after { content: ""; position: absolute; inset: auto 0 0; height: 4px; background: var(--c, var(--accent)); }
.group-card .body { padding: 13px 15px; display: flex; align-items: center; gap: 10px; }
.group-card .body > div { flex: 1; min-width: 0; }
.group-card p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-card { cursor: pointer; display: flex; flex-direction: column; gap: 12px; transition: transform .15s; }
.device-card:hover { transform: translateY(-2px); }
.device-card .top { display: flex; align-items: center; gap: 12px; }
.os-icon { width: 42px; height: 42px; border-radius: 11px; background: var(--panel-2); display: flex; align-items: center; justify-content: center; flex: none; }
.os-icon svg { width: 22px; height: 22px; }
.progress { height: 6px; border-radius: 9px; background: var(--panel-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--grad); transition: width .3s; }
.pair-code { font: 700 38px/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .12em; text-align: center; padding: 16px; border-radius: var(--radius); background: var(--bg); border: 1px dashed var(--accent); }
.dup-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dup-pair figure { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.dup-pair img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 10px; background: var(--panel-2); }
.qr { width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 8px; }

/* ------------------------------------------------------------------ Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(5, 6, 10, .7); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s ease-out;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 22px; animation: pop .18s ease-out;
}
.modal.wide { max-width: 1180px; padding: 0; display: grid; grid-template-columns: 1fr 340px; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.viewer { background: #000; display: flex; align-items: center; justify-content: center; min-height: 300px; max-height: calc(100vh - 32px); position: relative; }
.viewer img { max-width: 100%; max-height: calc(100vh - 32px); object-fit: contain; }
.viewer .nav-btn { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.45); color: #fff; border: 0; width: 42px; height: 42px; border-radius: 50%; cursor: pointer; font-size: 22px; }
.viewer .nav-btn.prev { left: 12px; } .viewer .nav-btn.next { right: 12px; }
.inspector { padding: 20px; overflow: auto; max-height: calc(100vh - 32px); display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 860px) {
  .modal.wide { grid-template-columns: 1fr; max-height: calc(100vh - 20px); overflow: auto; }
  .viewer, .viewer img { max-height: 55vh; }
  .inspector { max-height: none; }
  .modal-backdrop { padding: 10px; align-items: flex-end; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ------------------------------------------------------------------ Upload / Drop / Toast */
#drop-overlay {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center;
  background: rgba(99, 102, 241, .18); backdrop-filter: blur(3px); pointer-events: none;
}
#drop-overlay div { padding: 30px 46px; border: 2px dashed var(--accent); border-radius: 20px; background: var(--panel); font-size: 20px; font-weight: 700; }
#upload-panel {
  position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 80; width: 340px; max-width: calc(100vw - 24px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 14px;
}
@media (max-width: 860px) { #upload-panel { bottom: calc(80px + var(--safe-b)); right: 12px; } }
#upload-panel ul { list-style: none; margin: 10px 0 0; padding: 0; max-height: 220px; overflow: auto; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
#upload-panel li { display: flex; flex-direction: column; gap: 4px; }
#upload-panel li .name { display: flex; gap: 6px; justify-content: space-between; }
#upload-panel li .name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 10px 16px; border-radius: 11px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); font-weight: 600; font-size: 14px; animation: pop .2s ease-out; max-width: calc(100vw - 30px); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }

/* ------------------------------------------------------------------ Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; width: 100%;
  background: radial-gradient(800px 400px at 20% 0%, rgba(99,102,241,.25), transparent), radial-gradient(700px 400px at 90% 100%, rgba(236,72,153,.18), transparent); }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login .logo img { border-radius: 14px; }
.skeleton { background: linear-gradient(90deg, var(--panel-2), var(--panel), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
