:root {
  --sb-w: 210px;
  --sb-bg: #1e293b;
  --primary: #2563eb;
  --bg: #f1f5f9;
  --card: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --radius: 8px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: var(--bg); color: var(--text); }

/* ── Layout ── */
.app { display: flex; height: 100vh; height: 100dvh; }

/* ── Sidebar ── */
.sb {
  width: var(--sb-w); background: var(--sb-bg);
  display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sb-brand { padding: 1.1rem 1rem .9rem; border-bottom: 1px solid #334155; }
.sb-brand h2 { color: #f1f5f9; font-size: .95rem; font-weight: 700; }
.sb-brand p  { color: #64748b;  font-size: .72rem; margin-top: .15rem; }

.sb-nav { padding: .85rem .65rem; flex: 1; }
.sb-group-lbl {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: #475569;
  padding: .4rem .5rem .3rem;
}
.sb-subgrp-lbl {
  font-size: .84rem; font-weight: 600;
  color: #94a3b8;
  padding: .5rem .7rem;
  margin-top: .2rem;
  border-radius: 6px;
  display: flex; align-items: center; gap: .55rem;
  cursor: pointer; user-select: none;
  transition: background .12s, color .12s;
}
.sb-subgrp-lbl:hover { background: #263446; color: #cbd5e1; }
.sb-balken-hdr {
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem .7rem .4rem 1.5rem;
  font-size: .8rem; color: #64748b;
  cursor: pointer; user-select: none; border-radius: 6px;
  transition: background .12s, color .12s;
}
.sb-balken-hdr:hover { background: #1e2d3d; color: #94a3b8; }
.nav-item.sb-indent  { padding-left: 1.5rem; }
.nav-item.sb-indent2 { padding-left: 2.5rem; }
.sb-collapsed { display: none !important; }
.sb-chevron { transition: transform .15s; flex-shrink: 0; }
.sb-subgrp-lbl.collapsed .sb-chevron,
.sb-balken-hdr.collapsed .sb-chevron { transform: rotate(-90deg); }
.nav-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .5rem .7rem; border-radius: 6px;
  font-size: .84rem; color: #94a3b8;
  cursor: pointer; transition: background .12s, color .12s;
  user-select: none;
}
.nav-item:hover { background: #263446; color: #cbd5e1; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }

.sb-footer {
  padding: .65rem 1rem; border-top: 1px solid #334155;
  font-size: .7rem; color: #475569;
}

/* ── Main ── */
.main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 1.1rem 1.1rem max(6rem, calc(env(safe-area-inset-bottom) + 6rem)); display: flex; flex-direction: column; gap: 1rem;
}
.view { display: flex; flex-direction: column; gap: 1rem; }

/* ── Cards ── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.15rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card-title {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted);
  margin-bottom: .85rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

/* ── Datei-laden button ── */
.btn-datei-laden {
  display: inline-flex; align-items: center;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .42rem .9rem; font-size: .85rem; font-weight: 500;
  cursor: pointer; transition: background .12s, border-color .12s;
  user-select: none;
}
.btn-datei-laden:hover { background: #e2e8f0; border-color: #94a3b8; }

/* ── Item cards ── */
.item-list { display: flex; flex-direction: column; gap: .65rem; }

.item-card {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 7px; padding: .75rem .95rem;
}
.item-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .6rem;
}
.item-card-title {
  font-size: .78rem; font-weight: 600; color: var(--text);
}
.btn-remove {
  background: none; border: none; color: var(--muted);
  font-size: 1.15rem; line-height: 1; cursor: pointer;
  padding: .1rem .3rem; border-radius: 4px;
  transition: background .12s, color .12s;
}
.btn-remove:hover { background: #fee2e2; color: #ef4444; }

/* ── Field grid ── */
.fgrid {
  display: flex; flex-wrap: wrap; gap: .5rem .9rem;
  align-items: center;
}
.fgroup {
  display: flex; flex-direction: column; gap: .2rem;
}
.flbl {
  font-size: .68rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.finput {
  width: 100px; border: 1px solid var(--border); border-radius: 5px;
  padding: .36rem .5rem; font-size: .9rem; color: var(--text); outline: none;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.finput:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.finput.wide { width: 175px; }

.fselect {
  border: 1px solid var(--border); border-radius: 5px;
  padding: .36rem .5rem; font-size: .85rem; color: var(--text);
  background: #fff; outline: none; cursor: pointer; min-width: 155px;
  transition: border-color .15s;
}
.fselect:focus { border-color: var(--primary); }

.funit {
  font-size: .78rem; color: var(--muted);
  align-self: flex-end; margin-bottom: .38rem;
}
.fsep {
  align-self: flex-end; margin-bottom: .38rem;
  font-size: .85rem; color: var(--muted); font-weight: 600;
}

/* ── Add button ── */
.btn-add {
  display: flex; align-items: center; gap: .45rem;
  background: #fff; color: var(--primary);
  border: 2px dashed #93c5fd; border-radius: 7px;
  padding: .5rem 1.2rem; font-size: .86rem; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s;
  margin-top: .25rem;
}
.btn-add:hover { background: #eff6ff; border-color: var(--primary); }
.btn-add-icon { font-size: 1.1rem; line-height: 1; }

/* ── Lager type badges ── */
.type-loslager  { color: #0369a1; }
.type-festlager { color: #065f46; }
.type-einspan   { color: #7c3aed; }

/* ── Berechnung placeholder ── */
.placeholder-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .7rem; padding: 3rem 2rem;
  background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: .9rem; text-align: center;
}
.placeholder-box svg { opacity: .35; }

/* ── Counter badges in sidebar ── */
.sb-badge {
  margin-left: auto;
  background: #334155; color: #94a3b8;
  font-size: .67rem; font-weight: 700;
  border-radius: 10px; padding: .1rem .45rem;
  min-width: 1.4rem; text-align: center;
}
.nav-item.active .sb-badge { background: rgba(255,255,255,.25); color: #fff; }

/* ── Skizze ── */
.skizze-wrap {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  min-height: 262px;
}

/* ── Freimachen ── */
.freimachen-wrap {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-y: auto;
  min-height: 262px;
}

/* ── Responsive ── */
@media(max-width: 600px) { .sb { display: none; } }
