:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #dfe4ea;
  --text: #1b2530;
  --muted: #6b7a8a;
  --accent: #0f5c8c;
  --accent-light: #e8f1f7;
  --ok: #1e7d4f;
  --warn: #b5651d;
  --crit: #b3261e;
  --radius: 12px;
  --tap: 46px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.83rem; }
.error { color: var(--crit); font-size: 0.9rem; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.view { min-height: 100vh; }
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 28px 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 6px 28px rgba(20, 40, 60, .08);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.35rem; }
.login-card p { margin: 0 0 18px; }

/* ── Layout ────────────────────────────────────────────────────────────── */
#app-view { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px) 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--accent);
  color: #fff;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; letter-spacing: .3px; }
.topbar .muted { color: rgba(255,255,255,.75); flex: 1; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.45); }

main { padding: 16px; max-width: 780px; margin: 0 auto; }

h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 22px 0 4px; }

.row { display: flex; align-items: center; gap: 10px; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.row h2 { flex: 1; margin: 0; }

/* ── Karten / Formulare ────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}
.form label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 12px;
  min-height: var(--tap);
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-light);
  border-color: var(--accent);
}
.search { margin: 0 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap);
  padding: 10px 18px;
  font-size: 1rem; font-weight: 600; font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
.btn.small { min-height: 38px; padding: 7px 13px; font-size: 0.9rem; width: auto; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--crit); border-color: #f0c9c6; }

/* ── Statistik ─────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column;
}
.stat b { font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.stat.warn b { color: var(--warn); }
.stat.crit b { color: var(--crit); }

/* ── Listen ────────────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.item.prio-hoch { border-left-color: var(--warn); }
.item.prio-kritisch { border-left-color: var(--crit); }
.item.done { opacity: .55; }
.item-head { display: flex; align-items: baseline; gap: 8px; }
.item-head b { font-size: 1.02rem; letter-spacing: .4px; }
.item-head .spacer { flex: 1; }
.item-sub { font-size: 0.86rem; color: var(--muted); margin-top: 2px; }
.badge {
  font-size: 0.74rem; font-weight: 700; padding: 2px 8px;
  border-radius: 20px; background: var(--accent-light); color: var(--accent);
  white-space: nowrap;
}
.badge.overdue { background: #fdeceb; color: var(--crit); }
.badge.soon { background: #fdf1e5; color: var(--warn); }
.badge.ok { background: #e8f5ee; color: var(--ok); }
.qty { font-variant-numeric: tabular-nums; }
.item-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ── Tabbar ────────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 7px;
  font-size: 1.15rem; font-family: inherit;
  background: none; border: 0; color: var(--muted); cursor: pointer;
}
.tabbtn span { font-size: 0.68rem; font-weight: 600; }
.tabbtn.active { color: var(--accent); }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: #1b2530; color: #fff;
  padding: 11px 18px; border-radius: 10px;
  font-size: 0.9rem; max-width: 88vw; text-align: center; z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* ── Ergänzungen: Auftrags-Detail, Tabellen, Kleinigkeiten ──────────────── */
.topbar #who { color: rgba(255, 255, 255, .78); flex: 1; }

.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: .2px;
}
.mb { margin-bottom: 12px; width: auto; }
.mt { margin-top: 12px; }
.mt2 { margin-top: 14px; margin-bottom: 10px; }

.item[role="button"] { cursor: pointer; }
.item[role="button"]:active { background: var(--accent-light); }

/* Positions-Tabelle – kompakt, auch bei 60+ Zeilen */
.ttable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.92rem;
}
.ttable th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--card);
}
.ttable td {
  padding: 7px 4px;
  border-bottom: 1px solid #eef1f4;
  vertical-align: middle;
}
.ttable tr:last-child td { border-bottom: 0; }
.ttable .r { text-align: right; }
.ttable .qty { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ttable .qty.open { font-weight: 700; color: var(--crit); }
.ttable tr.row-done { opacity: .55; }

.xbtn {
  background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 1rem; line-height: 1;
  padding: 6px 8px; border-radius: 6px;
}
.xbtn:active { background: #fdeceb; color: var(--crit); }

code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--accent-light);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}

/* ── Editor: Auftragskopf + TKZ-Zeile ───────────────────────────────────── */
.lbl {
  display: block;
  margin-bottom: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  color: var(--muted);
}
.lbl input, .lbl select, .lbl textarea {
  margin-top: 5px;
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
}
input.big {
  font-size: 1.15rem;
  font-weight: 600;
  padding: 14px 12px;
}

/* TKZ + Anzahl + Plus in einer Zeile */
.tkz-row {
  display: grid;
  grid-template-columns: 1fr 96px auto;
  gap: 8px;
  align-items: stretch;
}
.tkz-row input { margin-top: 0; }
.tkz-row .qty-in { max-width: 96px; text-align: right; }
.btn.plus {
  width: 56px;
  min-width: 56px;
  padding: 0;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}
@media (max-width: 380px) {
  .tkz-row { grid-template-columns: 1fr 80px auto; }
  .tkz-row .qty-in { max-width: 80px; }
}

/* KIT-Badge (lange Nummern wie 330607KIT0296) */
.badge.kit {
  background: #eef1f5;
  color: #46566a;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.68rem;
  letter-spacing: .2px;
  font-weight: 600;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Vorschlagsliste (Autovervollständigung) ────────────────────────────── */
.suggest {
  position: fixed;
  z-index: 80;
  max-height: 46vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(20, 40, 60, .16);
  padding: 4px;
}
.suggest-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 0.95rem;
  cursor: pointer;
}
.suggest-row .mono { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-row .suggest-n {
  font-size: 0.74rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.suggest-row:hover, .suggest-row.on {
  background: var(--accent-light);
}
