:root {
  --bg: #0d1117; --panel: #161b22; --panel-2: #1c232d; --border: #2a3340;
  --text: #e6edf3; --muted: #8b98a8; --accent: #4f8cff; --accent-h: #6a9fff; --danger: #ff6b6b;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
h1 { font-size: clamp(1.4rem, 4vw, 2rem); margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .25rem; }
.muted { color: var(--muted); }

.auth { display: grid; place-items: center; padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom)); }
.card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem 1.5rem; box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.brand { display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.brand h1 { margin: 0; font-size: 1.4rem; }
.logo {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8a5cff); font-weight: 700; font-size: .9rem; color: #fff;
}

form label { display: block; margin: 1rem 0 .35rem; font-size: .9rem; color: var(--muted); }
input {
  width: 100%; padding: .8rem .9rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.25); }
.alert { background: rgba(255,107,107,.12); border: 1px solid rgba(255,107,107,.4); color: var(--danger); padding: .7rem .9rem; border-radius: 10px; margin-top: 1rem; font-size: .95rem; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  padding: .75rem max(1rem, env(safe-area-inset-right)) .75rem max(1rem, env(safe-area-inset-left));
  background: rgba(22,27,34,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .brand { margin: 0; }
.userbox { display: flex; align-items: center; gap: .75rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.grid { display: grid; gap: 1rem; margin-top: 1.5rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }

@media (max-width: 480px) {
  .card { padding: 1.5rem 1.1rem; }
  .userbox .muted { display: none; }
  input { font-size: 16px; }
}

.narrow { max-width: 480px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem 1.5rem; margin-top: 1rem; }
.alert.ok { background: rgba(63,185,120,.12); border-color: rgba(63,185,120,.4); color: #5fd08f; }
a.brand { color: inherit; text-decoration: none; }
a.muted { text-decoration: none; }
a.muted:hover { color: var(--text); }
.stat { font-size: 2rem; font-weight: 700; margin: .5rem 0 0; }
.tile.wide { grid-column: 1 / -1; min-height: 160px; }

.nav { display: flex; gap: .25rem; flex: 1; margin-left: .75rem; }
.nav a { color: var(--muted); text-decoration: none; padding: .45rem .75rem; border-radius: 8px; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.on { color: var(--text); background: var(--panel-2); }
.resform h2 { margin-bottom: .25rem; }
.fields { display: grid; gap: 0 1rem; grid-template-columns: 2fr 1fr 2fr; }
.actions { display: flex; gap: .75rem; margin-top: 1.25rem; }
.list { list-style: none; margin: 1.25rem 0 0; padding: 0; display: grid; gap: .6rem; }
.row { display: flex; align-items: center; gap: .9rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .grow strong { overflow-wrap: anywhere; }
.small { font-size: .85rem; }
.ico { flex: none; width: 44px; height: 44px; display: grid; place-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.ico img { width: 36px; height: 36px; object-fit: contain; }
.ico img.broken { visibility: hidden; }
.price { font-weight: 600; white-space: nowrap; }
.rowact { display: flex; gap: .5rem; }
.rowact form { margin: 0; }
.empty { margin-top: 1.5rem; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; margin-left: 0; }
  .fields { grid-template-columns: 1fr; }
  .row { flex-wrap: wrap; }
  .row .grow { flex-basis: calc(100% - 140px); }
  .rowact { width: 100%; justify-content: flex-end; }
}

/* --- Rohstoffe: kompakte Buttons, Dialog --- */
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.pagehead p { margin: 0 0 .5rem; }
.rowact form { width: auto; }
.row { padding: .6rem .8rem; }

dialog {
  width: calc(100% - 2rem); max-width: 540px; padding: 1.5rem; margin: auto;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(2px); }
dialog h2 { font-size: 1.25rem; margin: 0; }

@media (max-width: 720px) {
  .row { display: grid; grid-template-columns: 44px 1fr auto; gap: .5rem .75rem; }
  .row .grow { flex-basis: auto; }
  .rowact { grid-column: 1 / -1; width: auto; justify-content: flex-end; }
        }


/* --- Einheitliches Button-System --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  height: 40px; padding: 0 1rem; border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-size: .95rem; font-weight: 600; line-height: 1; white-space: nowrap;
  text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #26303c; border-color: #3a4656; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--panel-2); }
.btn-danger { background: transparent; border-color: rgba(255,107,107,.45); color: var(--danger); }
.btn-danger:hover { background: rgba(255,107,107,.14); border-color: rgba(255,107,107,.7); }
.btn-sm { height: 34px; padding: 0 .8rem; font-size: .88rem; }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.btn svg { display: block; flex: none; }
.btn-block { width: 100%; }
form .btn-block { margin-top: 1.5rem; }
.rowact form { margin: 0; }

@media (max-width: 720px) {
  .pagehead .btn { width: 100%; }
}

/* Popup-Aufbau */
.dlghead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .25rem; }
.dlghead .btn-icon { margin-right: -.4rem; }
.dlgactions {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: center;
  margin: 1.5rem -1.5rem -1.5rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border);
  background: rgba(0,0,0,.15); border-radius: 0 0 14px 14px;
}
.dlgactions .cancel { margin-right: auto; }
.dlgactions form, .dlgactions .btn { margin-top: 0; }
@media (max-width: 720px) {
  .dlgactions { flex-direction: column-reverse; align-items: stretch; }
  .dlgactions .btn { width: 100%; white-space: normal; }
  .dlgactions .cancel { margin: 0; }
}

/* --- Checkbox --- */
.check { position: relative; flex: none; display: grid; place-items: center; width: 28px; height: 44px; cursor: pointer; }
.check input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.check .box {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid #3a4656; background: var(--bg);
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.check .box::after {
  content: ""; width: 5px; height: 10px; margin-top: -2px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0); transition: transform .12s;
}
.check:hover .box { border-color: var(--accent); }
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after { transform: rotate(45deg) scale(1); }
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.row.is-checked { border-color: rgba(79,140,255,.45); }
.listfoot { display: flex; justify-content: center; margin-top: 1.25rem; }
@media (max-width: 720px) {
  .row { grid-template-columns: 28px 44px 1fr auto; }
  .listfoot .btn { width: 100%; }
}

/* --- Backups --- */
.backups { max-width: 760px; margin: 2.5rem auto 0; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.sech { font-size: 1.4rem; margin: 0 0 .25rem; }
.badge { font-size: .75rem; padding: .2rem .55rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge-manual { color: #8fb4ff; border-color: rgba(79,140,255,.4); }
.badge-prerestore { color: #e6b450; border-color: rgba(230,180,80,.4); }
.bkrow .rowact { margin-left: .25rem; }
@media (max-width: 720px) {
  .bkrow { grid-template-columns: 1fr auto; }
  .bkrow .rowact { grid-column: 1 / -1; margin: 0; }
  .backups .pagehead .btn { width: 100%; }
  .backups .pagehead form { width: 100%; }
}

/* --- Produkte, Bestand, ??? --- */
.unknown { color: #e6b450; }
.err { color: #e6b450; }
.price.unknown { font-weight: 700; }
.stockbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem .75rem; margin: .25rem 0 .75rem; }
.stockbar form { margin: 0; }
.headbtns { display: flex; gap: .6rem; flex-wrap: wrap; }
.prodlist { gap: .8rem; }
.pcard { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; }
.pcard.is-checked { border-color: rgba(79,140,255,.45); }
.phead { display: flex; align-items: center; gap: .8rem; }
.phead .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .8rem 0 .6rem; }
.figures div { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; }
.figures dt { color: var(--muted); font-size: .78rem; }
.figures dd { margin: 0; font-weight: 700; font-size: 1.05rem; }
.figures dd small { font-weight: 500; color: var(--muted); }
.pos { color: #5fd08f; } .neg { color: var(--danger); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font-size: .82rem; padding: .25rem .6rem; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); }
.chip.sub { border-color: rgba(138,92,255,.5); }
.chip.unknown { border-color: rgba(230,180,80,.5); }
.chip .cv { color: var(--muted); margin-left: .25rem; }
.chip.unknown .cv { color: #e6b450; font-weight: 700; }
dialog.wide { max-width: 680px; max-height: calc(100dvh - 2rem); overflow: auto; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.subh { font-size: 1rem; margin: 1.25rem 0 .25rem; }
.ing { display: grid; grid-template-columns: 1fr 110px 34px; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.ing input { padding: .6rem .75rem; }
.preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: 1rem; }
.preview:empty { display: none; }
.preview div { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; display: flex; flex-direction: column; }
.preview span { color: var(--muted); font-size: .78rem; }
select { width: 100%; padding: .8rem .9rem; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.implist { margin-top: 1rem; max-height: 45dvh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.impitem { display: flex; gap: .7rem; align-items: flex-start; padding: .6rem .8rem; border-bottom: 1px solid var(--border); cursor: pointer; margin: 0; color: var(--text); font-size: .95rem; }
.impitem:last-child { border-bottom: 0; }
.impitem input { width: auto; margin-top: .3rem; accent-color: var(--accent); }
.impitem.done { opacity: .55; cursor: default; }
.impitem em { font-style: normal; color: var(--muted); font-weight: 400; font-size: .8rem; }
.impbody { display: flex; flex-direction: column; min-width: 0; }
@media (max-width: 720px) {
  .fields2 { grid-template-columns: 1fr; }
  .figures, .preview { grid-template-columns: 1fr; }
  .figures div { display: flex; justify-content: space-between; align-items: center; }
  .ing { grid-template-columns: 1fr 84px 34px; }
  .headbtns { width: 100%; } .headbtns .btn { flex: 1; }
  .phead { flex-wrap: wrap; }
}
