:root {
  --bg: #0F1A1F;
  --surface: #16262C;
  --surface-2: #1D323A;
  --line: #2A444E;
  --line-soft: #213840;
  --text: #E7EFEF;
  --muted: #8CA5AD;
  --amber: #E9A13B;
  --red: #E2614A;
  --green: #57BE9C;
  --blue: #6FA8C7;

  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;

  --r: 10px;
  --pad: 16px;
  --nav-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }

/* ---------- Grundgerüst ---------- */

.app {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 26, 31, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
  padding: calc(env(safe-area-inset-top) + 12px) var(--pad) 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

header.top h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 620;
  letter-spacing: -0.015em;
}

header.top .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

main { padding: var(--pad); max-width: 780px; margin: 0 auto; }

/* ---------- Navigation ---------- */

nav.bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(22, 38, 44, 0.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

nav.bottom button {
  background: none;
  border: 0;
  padding: 9px 4px 10px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  border-top: 2px solid transparent;
  margin-top: -1px;
}

nav.bottom button svg { width: 21px; height: 21px; }
nav.bottom button[aria-current="page"] { color: var(--text); border-top-color: var(--amber); }

/* ---------- Bausteine ---------- */

.eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 22px 0 8px;
}
.eyebrow:first-child { margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 10px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
.row:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title {
  display: block;
  font-weight: 560;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row .sub {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .num { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.row .side { flex: 0 0 auto; text-align: right; line-height: 1.5; }

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.tag.amber { color: var(--amber); border-color: #63481f; }
.tag.green { color: var(--green); border-color: #2b5a4c; }
.tag.red   { color: var(--red);   border-color: #6a3229; }
.tag.solid-red { background: #3A1D18; color: var(--red); border-color: #6a3229; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  padding: 12px 14px;
}
.stat .k {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat .v {
  font-family: var(--mono);
  font-size: 23px;
  letter-spacing: -0.02em;
  margin-top: 3px;
}
.stat .v small { font-size: 13px; color: var(--muted); letter-spacing: 0; }

.catbar { margin-bottom: 12px; }
.catbar .catbar-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 5px;
}
.catbar .catbar-head .name { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catbar .catbar-head .amt { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.catbar .track { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.catbar .fill { height: 100%; background: var(--blue); border-radius: 3px; }

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--r);
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Spulen-Ring: das Erkennungszeichen ---------- */

.spool {
  position: relative;
  width: 46px; height: 46px;
  flex: 0 0 46px;
}
.spool svg { transform: rotate(-90deg); }
.spool .rim {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(231, 239, 239, 0.14);
  pointer-events: none;
}
.spool .core {
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

/* ---------- Formulare ---------- */

.field { margin-bottom: 11px; }
.field label {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
}
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible,
button:focus-visible, .row:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}
.field textarea { min-height: 74px; resize: vertical; }
.field input[type="color"] { padding: 3px; height: 42px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 520;
}
.btn.primary { background: var(--amber); border-color: var(--amber); color: #17110A; font-weight: 620; }
.btn.danger { color: var(--red); border-color: #6a3229; background: transparent; }
.btn.ghost { background: transparent; }
a.btn { color: var(--text); text-decoration: none; text-align: center; }
.btn:active { transform: translateY(1px); }
.btn.wide { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

.search {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  outline: none;
}

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--surface-2); color: var(--text); border-color: var(--muted); }

/* ---------- Overlay ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(8, 14, 17, 0.66);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 620px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 18px var(--pad) calc(24px + env(safe-area-inset-bottom));
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: 0; } }
.sheet h2 { margin: 0 0 14px; font-size: 17px; letter-spacing: -0.015em; }
.sheet .close {
  float: right;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  max-width: 90vw;
}

.doc {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 7px;
  font-size: 13.5px;
}
.doc a { flex: 1; color: var(--text); text-decoration: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 17px; }

/* ---------- Login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--pad);
}
.login form { width: 100%; max-width: 320px; }
.login .mark {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: 6px;
}
.login h1 { font-size: 24px; margin: 0 0 20px; letter-spacing: -0.02em; }
.err { color: var(--red); font-size: 13.5px; margin-top: 10px; min-height: 18px; }

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .app { padding-bottom: 0; padding-left: 208px; }
  nav.bottom {
    top: 0; right: auto;
    width: 208px;
    grid-template-columns: 1fr;
    align-content: start;
    border-top: 0;
    border-right: 1px solid var(--line);
    padding-top: 22px;
    gap: 2px;
  }
  nav.bottom button {
    flex-direction: row;
    justify-content: flex-start;
    gap: 11px;
    padding: 11px 18px;
    font-size: 12px;
    border-top: 0;
    border-left: 2px solid transparent;
  }
  nav.bottom button[aria-current="page"] { border-left-color: var(--amber); background: var(--surface-2); }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; border-bottom: 1px solid var(--line); padding-bottom: 24px; }
  .toast { bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
