: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;
}
.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; }

.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;
}

/* ── 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);
}

/* ── Step card header ── */
.step-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .85rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

/* ── Field rows ── */
.flbl {
  min-width: 44px; display: flex; align-items: center; justify-content: flex-end;
  font-size: .95rem;
}
.feq { color: var(--muted); font-size: .95rem; }
.finput {
  width: 105px; border: 1px solid var(--border); border-radius: 5px;
  padding: .38rem .5rem; font-size: .9rem; color: var(--text); outline: none;
  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:disabled { cursor: not-allowed; opacity: .55; background: #f8fafc; }
.finput[readonly]  { background: #f8fafc; cursor: default; color: var(--muted); }
.khint { font-size: .75rem; color: var(--muted); white-space: nowrap; }

/* ── Unknown checkbox ── */
.bc-unk-lbl {
  display: flex; align-items: center; gap: .3rem;
  font-size: .78rem; color: var(--muted);
  cursor: pointer; margin-left: .4rem; user-select: none;
}
.bc-unk-lbl input[type="checkbox"] { cursor: pointer; }

/* ── Input grids ── */
.za-grid {
  display: grid;
  grid-template-columns: max-content max-content 105px max-content;
  column-gap: .45rem; row-gap: .55rem;
  align-items: center;
}
.za-grid-5 {
  display: grid;
  grid-template-columns: max-content max-content 105px max-content auto;
  column-gap: .45rem; row-gap: .55rem;
  align-items: center;
}
.za-field { display: contents; }

/* ── Remove button ── */
.btn-remove-step {
  background: none; border: none; color: var(--muted);
  font-size: 1.25rem; line-height: 1; cursor: pointer;
  padding: .1rem .35rem; border-radius: 4px;
  transition: background .12s, color .12s; flex-shrink: 0;
}
.btn-remove-step:hover { background: #fee2e2; color: #ef4444; }

/* ── Add-step button ── */
.btn-add-step {
  display: flex; align-items: center; gap: .45rem;
  background: #fff; color: var(--primary);
  border: 2px dashed var(--primary); border-radius: 8px;
  padding: .5rem 1.4rem; font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: background .15s, color .15s;
}
.btn-add-step:hover { background: #eff6ff; }
.btn-add-icon { font-size: 1.1rem; line-height: 1; }

/* ── Berechnen button ── */
.btn-berechnen {
  background: var(--primary); color: #fff;
  border: none; border-radius: 6px;
  padding: .55rem 1.6rem; font-size: .92rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
  letter-spacing: .02em;
}
.btn-berechnen:hover { background: #1d4ed8; }
.btn-berechnen:active { background: #1e40af; }

/* ── IO Buttons ── */
.btn-io {
  background: #fff; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .48rem 1rem; font-size: .84rem; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  display: flex; align-items: center; gap: .35rem;
}
.btn-io:hover { background: #f1f5f9; border-color: #cbd5e1; color: var(--text); }

/* ── Result display ── */
.bc-section-lbl {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
  margin: .9rem 0 .35rem;
}
.bc-section-lbl:first-child { margin-top: 0; }
.bc-eq-block {
  display: flex; flex-direction: column; gap: .45rem;
  padding: .65rem .9rem;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
}
.bc-eq-row {
  display: flex; align-items: baseline; gap: .6rem;
  font-size: .92rem; line-height: 1.6;
}
.bc-error { color: #ef4444; font-size: .88rem; margin-top: .6rem; }

/* ── Rechenweg ── */
.bc-rechenweg {
  display: flex; flex-direction: column; gap: .55rem;
  margin: .35rem 0 .55rem;
}
.bc-step {
  padding: .5rem .9rem;
  background: #f0f9ff; border-left: 3px solid #60a5fa;
  border-radius: 0 6px 6px 0;
  display: flex; flex-direction: column; gap: .4rem;
  overflow-x: auto;
}
.bc-step-line { font-size: .88rem; line-height: 1.6; }

/* ── Mode Toggle ── */
.gk-mode-toggle { display: flex; gap: .5rem; flex-wrap: wrap; }
.gk-mode-btn {
  padding: .38rem 1.1rem; border-radius: 6px;
  border: 1px solid var(--border); background: #fff;
  font-size: .86rem; font-weight: 600; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.gk-mode-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.gk-mode-btn:hover:not(.active) { background: #f1f5f9; }

/* ── Teil-Row (card-based shape input) ── */
.teil-list { display: flex; flex-direction: column; gap: .5rem; }
.teil-row {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden;
}
.teil-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .38rem .65rem;
  background: #f1f5f9; border-bottom: 1px solid var(--border);
}
.teil-body {
  display: flex; flex-direction: column; gap: .32rem;
  padding: .5rem .7rem .5rem 1.9rem;
}
.teil-sep-h { height: 1px; background: var(--border); margin: .15rem 0; }
.teil-sign {
  font-size: .78rem; font-weight: 700; min-width: 10px; text-align: center; flex-shrink: 0;
}
.teil-sign.addier { color: #22c55e; }
.teil-sign.abzug  { color: #ef4444; }
.teil-form-sel {
  flex: 1; border: 1px solid var(--border); border-radius: 4px;
  padding: .28rem .4rem; font-size: .84rem; color: var(--text);
  background: #fff; outline: none; cursor: pointer;
}
.teil-form-sel:focus { border-color: var(--primary); }
.teil-field {
  display: flex; align-items: center; gap: .4rem; font-size: .86rem;
}
.teil-field-lbl {
  min-width: 24px; color: var(--muted); font-size: .86rem; text-align: right;
}
.teil-field input[type="number"] {
  width: 110px; border: 1px solid var(--border); border-radius: 4px;
  padding: .3rem .45rem; font-size: .86rem; color: var(--text); background: #fff; outline: none;
}
.teil-field input[type="number"]:focus {
  border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}
.teil-unit { font-size: .84rem; color: var(--muted); }
.teil-field-wrap { display: flex; flex-direction: column; gap: .1rem; }
.teil-hint { font-size: .7rem; color: var(--muted); padding-left: 28px; font-style: italic; }

/* ── Querschnitt-Tabelle ── */
.qs-table {
  width: 100%; border-collapse: collapse; font-size: .86rem;
  margin-top: .5rem;
}
.qs-table th {
  background: #f1f5f9; font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  padding: .45rem .6rem; border: 1px solid var(--border); text-align: left;
}
.qs-table td {
  padding: .42rem .6rem; border: 1px solid var(--border); vertical-align: middle;
}
.qs-table tr:nth-child(even) td { background: #f8fafc; }
.qs-table select, .qs-table input[type="number"] {
  width: 100%; border: 1px solid var(--border); border-radius: 4px;
  padding: .28rem .4rem; font-size: .84rem; color: var(--text);
  background: #fff; outline: none;
}
.qs-table select:focus, .qs-table input[type="number"]:focus {
  border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}
.qs-table .btn-remove-step { padding: .05rem .3rem; }

/* ── Ergebnis-Tabelle ── */
.res-table td { text-align: right; }
.res-table td:first-child,
.res-table td:nth-child(2) { text-align: left; }
.res-sum-row td {
  font-weight: 700;
  border-top: 2px solid #94a3b8;
  background: #f1f5f9;
}

/* ── Skizze ── */
.gk-sketch-wrap {
  border: 1px solid var(--border); border-radius: 6px;
  background: #fafafa; overflow: hidden;
}

/* ── Placeholder ── */
.placeholder-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .75rem; padding: 3rem 1rem; text-align: center;
}
.placeholder-icon {
  width: 52px; height: 52px; border-radius: 12px;
  background: #eff6ff; display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.placeholder-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.placeholder-sub   { font-size: .85rem; color: var(--muted); max-width: 320px; line-height: 1.5; }

/* ── Responsive sidebar ── */
@media(max-width: 600px) { .sb { display: none; } }
